This patch adds "--gauge" and "--xgauge" options, and implements corresponding progress callbacks that produce output for the 'dialog' utility: http://invisible-island.net/dialog/dialog.html
The simple "--gauge" just emits percentage numbers, line by line, while "--xgauge" outputs extended information to update the dialog prompt. Both are meant for directly piping the output: sunxi-fel -g <...> | dialog --gauge "FEL upload progress" 6 70 Signed-off-by: Bernhard Nortmann <[email protected]> --- fel.c | 8 ++++++++ progress.c | 40 ++++++++++++++++++++++++++++++++++++++++ progress.h | 2 ++ 3 files changed, 50 insertions(+) diff --git a/fel.c b/fel.c index 0afc160..fb932d6 100644 --- a/fel.c +++ b/fel.c @@ -1123,6 +1123,8 @@ int main(int argc, char **argv) printf("Usage: %s [options] command arguments... [command...]\n" " -v, --verbose Verbose logging\n" " -p, --progress Show progress bar on larger transfers\n" + " -g, --gauge Output progress for \"dialog --gauge\"\n" + " -gg, --xgauge Extended gauge output (updates prompt)\n" " -np, --noprogress No (more) progress display after this\n" "\n" " spl file Load and execute U-Boot SPL\n" @@ -1183,6 +1185,12 @@ int main(int argc, char **argv) } else if (strcmp(argv[1], "--progress") == 0 || strcmp(argv[1], "-p") == 0) { set_progress_callback(progress_bar); + } else if (strcmp(argv[1], "--gauge") == 0 || + strcmp(argv[1], "-g") == 0) { + set_progress_callback(progress_gauge); + } else if (strcmp(argv[1], "--xgauge") == 0 || + strcmp(argv[1], "-gg") == 0) { + set_progress_callback(progress_gauge_xxx); } else if (strcmp(argv[1], "--noprogress") == 0 || strcmp(argv[1], "-np") == 0) { set_progress_callback(NULL); diff --git a/progress.c b/progress.c index 047d079..92a7d22 100644 --- a/progress.c +++ b/progress.c @@ -124,3 +124,43 @@ void progress_bar(size_t total, size_t done, bool quick) if (done >= total) putchar('\n'); /* output newline when complete */ fflush(stdout); } + +/* + * Progress callback that emits percentage numbers, each on a separate line. + * The output is suitable for piping it into "dialog --gauge". + * + * sunxi-fel --gauge <...> \ + * | dialog --title "FEL upload progress" \ + * --gauge "" 5 70 + */ +void progress_gauge(size_t total, size_t done, bool UNUSED(quick)) +{ + if (total > 0) { + printf("%.0f\n", (float)done / total * 100); + fflush(stdout); + } +} + +/* + * A more sophisticated version of progress_gauge() that also updates the + * prompt (caption) with additional information. This uses a feature of + * the dialog utility that parses "XXX" delimiters - see 'man dialog'. + * + * sunxi-fel --xgauge <...> \ + * | dialog --title "FEL upload progress" \ + * --backtitle "Please wait..." \ + * --gauge "" 6 70 + */ +void progress_gauge_xxx(size_t total, size_t done, bool UNUSED(quick)) +{ + if (total > 0) { + double speed = rate(done, progress_elapsed()); + double eta = estimate(total - done, speed); + printf("XXX\n"); + printf("%.0f\n", (float)done / total * 100); + printf("%zu of %zu, %.1f kB/s, ETA %s\n", + done, total, kilo(speed), format_ETA(eta)); + printf("XXX\n"); + fflush(stdout); + } +} diff --git a/progress.h b/progress.h index 3254201..28d3443 100644 --- a/progress.h +++ b/progress.h @@ -37,5 +37,7 @@ void progress_update(size_t total, size_t done, bool quick); /* progress callback implementations for various display styles */ void progress_bar(size_t total, size_t done, bool quick); +void progress_gauge(size_t total, size_t done, bool quick); +void progress_gauge_xxx(size_t total, size_t done, bool quick); #endif /* _SUNXI_TOOLS_PROGRESS_H */ -- 2.4.6 -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
