diff options
author | lns <matzeton@googlemail.com> | 2019-12-25 19:18:19 +0100 |
---|---|---|
committer | lns <matzeton@googlemail.com> | 2019-12-25 19:18:19 +0100 |
commit | 25b6686948c1602ad0800d54bd2160970c245bca (patch) | |
tree | 73b6b0e229498fafae6506e6cbefc01f1e3f7f5a | |
parent | a8f78609f99b5f207099796a6b964f0856d5e3b8 (diff) |
show calculated xfer rate periodic
-rw-r--r-- | progressbar.c | 12 |
1 files changed, 10 insertions, 2 deletions
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); } |