Skip to content

Progress bar fixes#18

Merged
engdoreis merged 2 commits into
lowRISC:mainfrom
ziuziakowska:fix-progressbar
Jun 18, 2026
Merged

Progress bar fixes#18
engdoreis merged 2 commits into
lowRISC:mainfrom
ziuziakowska:fix-progressbar

Conversation

@ziuziakowska

Copy link
Copy Markdown
Contributor
  • In the first second of an operation, the time shows as ,, and then goes to 1s, after a second has elapsed. Update this to display seconds always (e.g 0s, -> 1s,, 59s, -> 1m0s,) so that even if an operation took no time at all it still shows the duration.
  • If the printed length of the throughput section shrunk in size (e.g rate measured in XXX KiB/s rises to X MiB/s), garbage characters would be visible at the end of the line (usually an additional /s). Track the last printed width so that if it gets smaller, the difference is overwritten with spaces, and then backspace to the current printed length.

@ziuziakowska ziuziakowska requested a review from engdoreis June 17, 2026 16:26
Comment thread lib/visuals/progressbar.hh Outdated
Comment on lines +54 to +68
std::cout << "] " << percent_str << "\033[33m" << " " << tp_str << "\033[0m";

if (tp) {
if (this->last_length > print_length) {
/* There are some trailing characters left over from the last
* time throughput was printed. Overwrite them with spaces,
* and then backspace to the current length. */
int diff = this->last_length - print_length;
for (int i = 0; i < diff; i++) {
std::cout << " ";
}
for (int i = 0; i < diff; i++) {
std::cout << "\b";
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using width padding is more idiomatic, I didn't test, but I think this would work?

Suggested change
std::cout << "] " << percent_str << "\033[33m" << " " << tp_str << "\033[0m";
if (tp) {
if (this->last_length > print_length) {
/* There are some trailing characters left over from the last
* time throughput was printed. Overwrite them with spaces,
* and then backspace to the current length. */
int diff = this->last_length - print_length;
for (int i = 0; i < diff; i++) {
std::cout << " ";
}
for (int i = 0; i < diff; i++) {
std::cout << "\b";
}
}
int size = std::max(this->last_length, print_length);
auto bar = std::format( "] {} \033[33m {} \033[0m", percent_str, tp_str);
std::print("{:<{}}\b", bar, size);

@ziuziakowska ziuziakowska Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work in overwriting the excess text, but this would only backspace once at the end, and not back to the current length of the line, so there would be some trailing spaces. I think although padding lets you choose an arbitrary padding character, it cannot be used to just print a character n times as padding is part of a full format specifier.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to make it more idiomatic/less noisy, what do you think?

Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
@engdoreis engdoreis merged commit be6c376 into lowRISC:main Jun 18, 2026
1 check passed
@ziuziakowska ziuziakowska deleted the fix-progressbar branch June 18, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants