Progress bar fixes#18
Merged
Merged
Conversation
engdoreis
reviewed
Jun 18, 2026
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"; | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
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); |
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
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>
7b8e007 to
1c9b8c0
Compare
engdoreis
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
,, and then goes to1s,after a second has elapsed. Update this to display seconds always (e.g0s,->1s,,59s,->1m0s,) so that even if an operation took no time at all it still shows the duration.XXX KiB/srises toX 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.