-
Notifications
You must be signed in to change notification settings - Fork 245
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
RFC: Redesign how progress bars are added to MultiProgress
#677
Comments
@djc Interested in any thoughts you have on this, when you have time :). |
BTW in the past I have tried to explain my concerns about |
Would be great to make this harder to break, thanks for writing this up! I think we'd want to avoid combinatorial API explosion which I also think making things nicer for users at the cost of a little more code to maintain is probably worth it. I don't like the I also think we should try to first expose this in a semver-compatible update, guiding users to the new API by way of |
Sounds like a plan, and I like the name Definitely agreed regarding the combinatorial explosion. As a first attempt, I think I can write some kind of macro to slap on |
I don't love macros for this kind of thing but I guess it might be the best way to deduplicate. |
I'll try with and without. I also don't love macros since they tend to break code completion in my IDE (RustRover). |
I believe the current
MultiProgress
API is error-prone and too easy to "hold wrong", and would like to suggest a small-ish redesign.MultiProgress
exists primarily to coordinate draws of multipleProgressBar
s.With the current API, you create a
ProgressBar
and add it to theMultiProgress
. These are two discrete steps:The problem is that it is very easy to accidentally cause the
ProgressBar
to be drawn before it is added to theMultiProgress
, i.e. at the spot marked(1)
. The most common offender isenable_steady_tick
(for spinners). But lots of other methods (e.g.set_message
) can cause a draw too.If the
MultiProgress
has been drawn by the time we get to(1)
, then it is already game over:pb
has likely corrupted the screen.Off the top of my head, the most recent occurrences I've seen are listed below (I could have sworn there are more, but I can't find them):
The safe "fix" is to ensure
ProgressBar
s are only mutated/customized after being added toMultiProgress
. For example:However, I think we can do better by ensuring the
ProgressBar
s destined for aMultiProgress
are never prematurely touched in the first place. We could replaceMultiProgress::add
withadd_pb
/add_progress
andadd_spinner
methods toMultiProgress
. (Similarly,insert_spinner_before
,insert_pb_after
, etc.)Obviously, this breaks backwards compatibility. But I think it will save users from a lot of troubleshooting and annoyance in the long term.
Another option would be to create some kind of proxy with a
ProgressBar
-like API, but which defers customizations/draws until added to aMultiProgress
. Then changeMultiProgress
to only take those instead ofProgressBar
. Example:This might be a little nicer for users, at the cost of more implementation effort.
The text was updated successfully, but these errors were encountered: