From 1638f9b0f12056206faabdbca32c576d92824039 Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Tue, 3 Oct 2017 16:40:23 +0200 Subject: [PATCH] shell: implement draw_progress() as a convenience function --- include/shell/progress.h | 3 +++ source/shell/Makefile | 1 + source/shell/progress.c | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 include/shell/progress.h create mode 100644 source/shell/progress.c diff --git a/include/shell/progress.h b/include/shell/progress.h new file mode 100644 index 0000000..c5b93df --- /dev/null +++ b/include/shell/progress.h @@ -0,0 +1,3 @@ +#pragma once + +void draw_progress(FILE *fp, unsigned long pos, unsigned max); diff --git a/source/shell/Makefile b/source/shell/Makefile index 897d1a3..43f54d0 100644 --- a/source/shell/Makefile +++ b/source/shell/Makefile @@ -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 diff --git a/source/shell/progress.c b/source/shell/progress.c new file mode 100644 index 0000000..145dbc3 --- /dev/null +++ b/source/shell/progress.c @@ -0,0 +1,22 @@ +#include + +#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); +}