-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/progress_bar: add module for managing a progress bar in stdout #12550
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one.
I'm not happy with the forced 68b per progress bar. See my suggestion on removing that for the simple use case.
sys/progress_bar/progress_bar.c
Outdated
|
||
/* Fully reprint the progress bar */ | ||
for (unsigned j = 0; j < PROGRESS_BAR_LENGTH; j++) { | ||
if (100 * j < (uint16_t)(progress_bar->value * PROGRESS_BAR_LENGTH)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change this to use 0-255 instead of 0-100, the two multiplications turn into shifts. Also, the assert on top of this function becomes obsolete. Similar at the call site.
Not sure that justifies not using percentages.
sys/progress_bar/progress_bar.c
Outdated
printf(PROGRESS_BAR_SUFFIX_CHARACTER); | ||
|
||
/* Display progress bar suffix if any */ | ||
if (progress_bar->suffix[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is redundant, printf will printf will not print if the string is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it here but kept the check on the prefix as otherwise some garbage is printed if nothing is set in the buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that possible? Is the structure allocated on the stack and not emptied?
Shouldn't printf("%s", { \0, ... })
print nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declaring the progress bar static works but not on the stack indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be because defined statically, it'll be zeroed. On the stack it has random contents unless cleared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be because defined statically, it'll be zeroed. On the stack it has random contents unless cleared.
Makes sense. Maybe there should be a note about this in the documentation. Another possibility is to introduce a progress_bar_init
function to ensure buffers are correctly cleared before using a progress bar allocated on the stack.
Thanks for your review @kaspar030! |
1f1b2bc
to
9365826
Compare
I pushed a couple of commits that makes the progress bar usable even with pyterm. It's a bit hacky (use ascii escape codes to save and restore the cursor position) but it works. Is it worth though ? |
24695a3
to
ac9e65d
Compare
ac9e65d
to
66cd544
Compare
66cd544
to
3f1ac65
Compare
@kaspar030 seems like your comments have been addressed, except for some style comments, are you ok with the changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK. Tested on native and arduino-mega2560.
Personally I don't agree with in-memory buffers within progress_bar_t, and the need to handle multiple progress bars within the library. But with the change to an independent progress_bar_print()
, that's now optional, so it won't hurt.
Contribution description
This PR add a module for managing a progress on the stdout of RIOT.
The feature makes use of ASCII escape codes to fully redraw the progress bar when the update function is called.
Note that the progress bar doesn't work well with pyterm as a redraw of the progress bar doesn't contain the
\n
character. It's possible to hack around this but the result is not nice.The goal of the progress bar is to display the download status of a firmware during an update (PR will come soon)
Testing procedure
Issues/PRs references
None