From 25b6686948c1602ad0800d54bd2160970c245bca Mon Sep 17 00:00:00 2001 From: lns Date: Wed, 25 Dec 2019 19:18:19 +0100 Subject: show calculated xfer rate periodic --- progressbar.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'progressbar.c') diff --git a/progressbar.c b/progressbar.c index fd949be..52c168f 100644 --- a/progressbar.c +++ b/progressbar.c @@ -139,6 +139,7 @@ struct file_info { struct { float xfer_rates[32]; size_t next_index; + float last_reported_rate; } xfer_rate_history; struct { struct winsize dimensions; @@ -349,7 +350,7 @@ static void show_positions(struct file_info * const finfo) prettify_with_units(finfo->current_position, curpos, sizeof curpos); prettify_with_units(finfo->max_size, maxpos, sizeof maxpos); - add_printable_buf(finfo, "[%s / %s]", curpos, maxpos); + add_printable_buf(finfo, "[%s/%s]", curpos, maxpos); } static void measure_realtime(struct timespec * const tp) @@ -409,8 +410,15 @@ static void show_rate(struct file_info * const finfo) /* update history */ finfo->xfer_rate_history.xfer_rates[xfer_rate_index % XFER_RATES_LENGTH] = new_xfer_rate; + /* do not show every updated rate; can be very annoying if values are changing e.g. between 10.0 and 9.0 */ + if (finfo->xfer_rate_history.next_index - 1 < XFER_RATES_LENGTH || + (finfo->xfer_rate_history.next_index - 1) % (XFER_RATES_LENGTH / 2) == 0) + { + finfo->xfer_rate_history.last_reported_rate = result; + } + /* print it to the output buffer after "prettified" and units appended */ - prettify_with_units(result, out, sizeof out); + prettify_with_units(finfo->xfer_rate_history.last_reported_rate, out, sizeof out); add_printable_buf(finfo, "[%s/s]", out); } -- cgit v1.2.3