-
Notifications
You must be signed in to change notification settings - Fork 657
refactor(cli/unstable): print progress bar when value
and max
are changed
#6664
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
base: main
Are you sure you want to change the base?
refactor(cli/unstable): print progress bar when value
and max
are changed
#6664
Conversation
value
and max
are changedvalue
and max
are changed
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6664 +/- ##
=======================================
Coverage 94.71% 94.71%
=======================================
Files 567 567
Lines 46778 46799 +21
Branches 6582 6585 +3
=======================================
+ Hits 44305 44326 +21
Misses 2431 2431
Partials 42 42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I don't see the point of calling the #print function every time the values are updated. If value is updated a lot then that can lead to a lot of unnecessary prints. |
I wouldn't say these prints are unnecessary. If there is a lot of progress, I think it is beneficial to see that reflected on the progress bar more than every second, no? |
No. I very likely could be updating |
I updated the PR so it checks every 100ms for updates. That way there is a new print every 100ms at most and only on changes while maintaining a mandatory print every second. |
@@ -162,8 +162,14 @@ const UNIT_RATE_MAP = new Map<Unit, number>([ | |||
* await bar.stop(); | |||
*/ | |||
export class ProgressBar { | |||
#hasUpdate = true; |
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 about using throttle
from @std/async/unstable-throttle
to throttle the too many calls? That has no delay when the print call is not throttled.
constructor(...) {
...
this.#throttledPrint = throttle(this.#print, 100)
}
set value(...) {
...
this.#throttledPrint()
}
What would be the maximum reasonable number of re-rendering in a second? |
Idk, but I think it would be better to leave that up to the user to decide. Looking at the docs, I could have sworn there was an option for them to control the frequency of the updates, but that doesn't seem to be the case. I think an inconsistent update interval though could give the effect that the program is having lag spikes and any "delta" values that are introduced or manually calculated via the formatter option can have big jumps up and down. |
Not sure if we should advertise to use the |
I see the point, but it feels weird that we can't update frequently to keep the delta calculation correct.. How about splitting the printing of progress bar and the calculation of delta of the value? |
Another option would be to provide delta calculations as properties. cli-progress and progress do this. |
This PR decodes buffers in tests and compares them to strings for easier comprehension.
It adds getters and setters for
value
andmax
which call#print()
when the value changes and also recalculatesunit
andrate
whenmax
changes.