From e490f5f4efbdeb4ac69bc18690050d5059229e22 Mon Sep 17 00:00:00 2001 From: lns Date: Thu, 26 Dec 2019 10:20:33 +0100 Subject: support for writing files (means that fd offset > previously stat'ed file) --- progressbar.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'progressbar.c') diff --git a/progressbar.c b/progressbar.c index ad3b794..93bf5ac 100644 --- a/progressbar.c +++ b/progressbar.c @@ -383,9 +383,13 @@ static void show_positions(struct terminal * const term, assert(finfo); prettify_with_units(finfo->current_position, curpos, sizeof curpos); - prettify_with_units(finfo->max_size, maxpos, sizeof maxpos); - - add_printable_buf(term, finfo, "[%s/%s]", curpos, maxpos); + /* if the user is currently writing/appending to a file, show only current offset */ + if (finfo->current_position <= finfo->max_size) { + prettify_with_units(finfo->max_size, maxpos, sizeof maxpos); + add_printable_buf(term, finfo, "[%s/%s]", curpos, maxpos); + } else { + add_printable_buf(term, finfo, "[%s WRITTEN]", curpos); + } } static void measure_realtime(struct timespec * const tp) @@ -470,6 +474,10 @@ static void show_progressbar(struct terminal const * const term, if (remaining_len < 16 || remaining_len >= sizeof buf) { return; } + /* do not show progressbar if someone writes/appendes to this file */ + if (finfo->current_position > finfo->max_size) { + return; + } float progress = (float)finfo->current_position / finfo->max_size; add_printable_buf(term, finfo, "[%.2f%%]", progress * 100.0f); -- cgit v1.2.3