From 54cd0614ef0035228afa902375bfcc63bc281c04 Mon Sep 17 00:00:00 2001 From: Alice Ziuziakowska Date: Wed, 17 Jun 2026 17:18:40 +0100 Subject: [PATCH 1/2] clear trailing characters in progress bar if printing less than before Signed-off-by: Alice Ziuziakowska --- lib/visuals/progressbar.hh | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/visuals/progressbar.hh b/lib/visuals/progressbar.hh index 8b02f9f..abb1c7c 100644 --- a/lib/visuals/progressbar.hh +++ b/lib/visuals/progressbar.hh @@ -6,10 +6,11 @@ #include "throughput.hh" struct ProgressBar { - bool finished = false; - int width = 100; - int total = 0; - float progress = 0; + bool finished = false; + int width = 100; + int total = 0; + float progress = 0; + int last_length = 0; std::string label; std::optional tp; @@ -40,10 +41,28 @@ struct ProgressBar { for (int i = 0; i < width; ++i) { std::print("{}", i < filled ? "■" : " "); } - std::cout << "] " << (int)(this->progress * 100) << "%\033[33m " << tp_str << "\033[0m " - << std::flush; + + std::string output = + std::format("] {}%\033[33m {}\033[0m", (int)(this->progress * 100), tp_str); + + std::cout << output; + + if (tp) { + auto current_length = output.length(); + if (this->last_length > current_length) { + /* There are some trailing characters left over from the last time + * throughput was printed. Overwrite them with spaces, and then + * backspace back to the current string length. */ + auto n = this->last_length - current_length; + std::cout << std::string(n, ' ') << std::string(n, '\b'); + } + this->last_length = current_length; + } + + std::cout << std::flush; + if (this->finished) { - std::println(""); + std::cout << '\n'; } } }; From 1c9b8c0783c21fb5ceec03bc33df09bc34b8c1bc Mon Sep 17 00:00:00 2001 From: Alice Ziuziakowska Date: Wed, 17 Jun 2026 17:19:06 +0100 Subject: [PATCH 2/2] always print seconds taken even if 0 Signed-off-by: Alice Ziuziakowska --- lib/visuals/throughput.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/visuals/throughput.hh b/lib/visuals/throughput.hh index 3993e4e..d46f8aa 100644 --- a/lib/visuals/throughput.hh +++ b/lib/visuals/throughput.hh @@ -67,7 +67,7 @@ struct Throughput { for (size_t i = 0; i < units.size(); ++i) { int part = (i < static_cast(units.size()) - 1) ? num % 60 : num; - if (part != 0) { + if (i == 0 || part != 0) { result = std::format("{}{}", part, units[i]) + result; } num /= 60;