console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.22k stars 238 forks source link

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

Closed matthewhchan closed 1 year ago

matthewhchan commented 1 year ago

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 commented 1 year ago

Happy to review your PR!

chris-laplante commented 1 year ago

Yes, I think that approach sounds OK.