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

Second ProgressBar can't be cleared if set_position before added to MultiProgress #502

Open
zhangkaizhao opened this issue Dec 25, 2022 · 2 comments

Comments

@zhangkaizhao
Copy link

I have no idea if this is a bug. Tested with indicatif == 0.17.2.

The good one which can be cleared when set_position after added to MultiProgress:

use indicatif::{MultiProgress, ProgressBar, ProgressStyle};

fn main() {
    let mp = MultiProgress::new();
    let pb = ProgressBar::new(0);
    let style = ProgressStyle::with_template("{msg}").unwrap();
    pb.set_style(style);
    mp.add(pb.clone());

    let pb2 = ProgressBar::new(100);
    let style2 = ProgressStyle::with_template("{bar}").unwrap();
    pb2.set_style(style2);
    mp.add(pb2.clone());
    pb2.set_position(0);
    pb2.finish_and_clear();

    pb.set_message("Good!");
    pb.finish();
}

Output:

Good!

The bad one which can't be cleared when set_position before added to MultiProgress:

use indicatif::{MultiProgress, ProgressBar, ProgressStyle};

fn main() {
    let mp = MultiProgress::new();
    let pb = ProgressBar::new(0);
    let style = ProgressStyle::with_template("{msg}").unwrap();
    pb.set_style(style);
    mp.add(pb.clone());

    let pb2 = ProgressBar::new(100);
    let style2 = ProgressStyle::with_template("{bar}").unwrap();
    pb2.set_style(style2);
    pb2.set_position(0);
    mp.add(pb2.clone());
    pb2.finish_and_clear();

    pb.set_message("Bad!");
    pb.finish();
}

Output:

░░░░░░░░░░░░░░░░░░░░
Bad!
@chris-laplante
Copy link
Collaborator

The problem here is that we cannot make any guarantees about what happens when you add a ProgressBar to a MultiProgress after that ProgressBar has already been drawn. In other words, MultiProgress assumes that ProgressBars that have been added to it have never been drawn before. So I am inclined to close this as "not a bug".

@djc
Copy link
Member

djc commented Dec 27, 2022

In other words, MultiProgress assumes that ProgressBars that have been added to it have never been drawn before.

Hmm, I'm not sure this is all that obvious? Why is this a necessary requirement? And how does it influence this particular behavior?

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

No branches or pull requests

3 participants