Skip to content
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

Feature Request: Add builder-like with_finish method to ProgressBarIter to set finish behavior #545

Closed
matthewhchan opened this issue Jun 1, 2023 · 2 comments · Fixed by #548

Comments

@matthewhchan
Copy link
Contributor

ProgressBarIter has a with_style method that lets you set the progress bar's style. But if you want to change the finish behavior, i.e. whether the progress bar remains on screen or is erased when it completes, you have to create a new ProgressBar and pass it to progress_with.

To keep the progress bar on screen when it finishes, I can do the following:

let v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
v.iter()
        .progress_with(ProgressBar::new(v.len() as u64).with_finish(ProgressFinish::AndLeave));

However, it's a bit verbose and needs to explicitly pass the length of the vector to ProgressBar::new.

I think it would be convenient to have the more concise form:

v.iter().progress().with_finish(ProgressFinish::AndLeave)

If this is acceptable from an API perspective, I can write the PR.

@djc
Copy link
Member

djc commented Jun 2, 2023

Happy to review your PR!

@chris-laplante
Copy link
Collaborator

Yes, I think that approach sounds OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants