Add ProgressBar::visual_index and clarify meaning of ProgressBar::index.#784
Open
chris-laplante wants to merge 3 commits intomainfrom
Open
Add ProgressBar::visual_index and clarify meaning of ProgressBar::index.#784chris-laplante wants to merge 3 commits intomainfrom
ProgressBar::visual_index and clarify meaning of ProgressBar::index.#784chris-laplante wants to merge 3 commits intomainfrom
Conversation
We no longer intend to expose this method as pub, but we should still give it better documentation.
f653cac to
f8e7d13
Compare
f8e7d13 to
caa2eb6
Compare
djc
reviewed
Apr 4, 2026
|
|
||
| /// If this [`ProgressBar`] is a member of a [`MultiProgress`](crate::MultiProgress), then return visual position | ||
| /// on screen. Otherwise, `None`. | ||
| pub fn visual_index(&self) -> Option<usize> { |
Member
There was a problem hiding this comment.
Do you think there's value in wrapping this up in a newtype VisualIndex? In some future we might be able to then use that in InsertLocation variants...
Or maybe, should this just be named index and we rename the private method to something else (members_index() maybe)?
Collaborator
Author
There was a problem hiding this comment.
I like the second option - I'll work on it later this weekend/Monday. In that case, I would still suggest we newtype the "members index" type, so that we don't accidentally get them confused internally either.
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.
MultiProgress::insertlets users insert a progress bar at a specified position within theMultiProgress. Before this PR, there was no way (besides keeping track manually) to know the position within theMultiProgressof aProgressBar.The
ProgressBar::indexmethod would be tempting ifpub, but not appropriate because it refers to the opaque index within theMultiState's data structures. This PR also clarifies its documentation.Something else that this PR enables is that users can now write their own
insert_after_with_offset(as suggested in #724 (comment)), i.e.mp.insert(other_pb.visual_index() + offset, pb)Supersedes #782 and #724