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

Finished progress bars are not preserved in MultiProgress::println #614

Closed
Mottl opened this issue Dec 17, 2023 · 6 comments
Closed

Finished progress bars are not preserved in MultiProgress::println #614

Mottl opened this issue Dec 17, 2023 · 6 comments

Comments

@Mottl
Copy link

Mottl commented Dec 17, 2023

MultiProgress::println doesn't redraw finished progress bars:

use std::time::Duration;
use indicatif::{MultiProgress, ProgressBar};

fn main() {
    eprintln!("Finished progress bars are preserved:");
    let multi = MultiProgress::new();
    for _ in 0..3 {
        let pg = multi.add(ProgressBar::new(5));
        for _ in 0..5 {
            std::thread::sleep(Duration::from_millis(100));
            pg.inc(1);
        }
        pg.finish();
    }

    eprintln!("\n\nFinished progress bars are not preserved");
    let multi = MultiProgress::new();
    for _ in 0..3 {
        let pg = multi.add(ProgressBar::new(5));
        for _ in 0..5 {
            std::thread::sleep(Duration::from_millis(100));
            pg.inc(1);
            multi.println("message").unwrap();
        }
        pg.finish();
    }
}
@Mottl Mottl changed the title Finished progress bars are not preserved when in MultiProgress::println Finished progress bars are not preserved in MultiProgress::println Dec 17, 2023
@djc
Copy link
Member

djc commented Dec 18, 2023

Have you tried setting the preferred behavior using ProgressBar::with_finish()?

@Mottl
Copy link
Author

Mottl commented Dec 18, 2023

Yes, the same behavior

@chris-laplante
Copy link
Collaborator

The ProgressBars are going out of scope so MultiProgress is forgetting about them. You need to clone them and keep them from getting dropped:

use std::time::Duration;
use indicatif::{MultiProgress, ProgressBar};

fn main() {
    eprintln!("Finished progress bars are preserved:");
    let multi = MultiProgress::new();
    for _ in 0..3 {
        let pg = multi.add(ProgressBar::new(5));
        for _ in 0..5 {
            std::thread::sleep(Duration::from_millis(100));
            pg.inc(1);
        }
        pg.finish();
    }

    eprintln!("\n\nFinished progress bars are not preserved");
    let mut keep = vec![];
    let multi = MultiProgress::new();
    for _ in 0..3 {
        let pg = multi.add(ProgressBar::new(5));
        keep.push(pg.clone());
        for _ in 0..5 {
            std::thread::sleep(Duration::from_millis(100));
            pg.inc(1);
            multi.println("message").unwrap();
        }
        pg.finish();
    }
}

@chris-laplante
Copy link
Collaborator

Related #595

@Mottl
Copy link
Author

Mottl commented Dec 19, 2023

Thanks a lot, Chris 👍️️️️️️
Probably, we could add this to FAQ or in docs.

@chris-laplante
Copy link
Collaborator

chris-laplante commented Dec 19, 2023

Thanks a lot, Chris 👍️️️️️️ Probably, we could add this to FAQ or in docs.

You're welcome! And yes absolutely, that's what #595 is about :)

@djc djc closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
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