shell: implement draw_progress() as a convenience function

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 4c2f4eab24
commit 1638f9b0f1
  1. 3
      include/shell/progress.h
  2. 1
      source/shell/Makefile
  3. 22
      source/shell/progress.c

@ -0,0 +1,3 @@
#pragma once
void draw_progress(FILE *fp, unsigned long pos, unsigned max);

@ -5,5 +5,6 @@ obj-y += source/shell/echo.o
obj-y += source/shell/flash.o
obj-y += source/shell/ftl.o
obj-y += source/shell/mufs.o
obj-y += source/shell/progress.o
obj-y += source/shell/rtc.o
obj-y += source/shell/version.o

@ -0,0 +1,22 @@
#include <stdio.h>
#define TERM_WIDTH 80
void draw_progress(FILE *fp, unsigned long pos, unsigned long max)
{
unsigned long head = (TERM_WIDTH - 2) * pos / max;
unsigned long i;
fputc('[', fp);
for (i = 0; i <= head; ++i)
fputc('#', fp);
for (; i < (TERM_WIDTH - 2); ++i)
fputc(' ', fp);
fputc(']', fp);
for (i = 0; i < TERM_WIDTH; ++i)
fputc('\b', fp);
}
Loading…
Cancel
Save