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

Allow logging above the progress bar #41

Merged
merged 1 commit into from Apr 1, 2018
Merged

Conversation

kpcyrd
Copy link
Contributor

@kpcyrd kpcyrd commented Mar 31, 2018

This allows logging some information without interfering with the progress bar.

extern crate indicatif;

use std::thread;
use std::time::Duration;

use indicatif::ProgressBar;

fn main() {
    let pb = ProgressBar::new(100);
    for i in 0..100 {
        thread::sleep(Duration::from_millis(250));
        pb.println(format!("[+] finished #{}", i));
        pb.inc(1);
    }
    pb.finish_with_message("done");
}

Resolves #27

@mitsuhiko
Copy link
Collaborator

Does this work if a line in the log is wrapped?

@kpcyrd
Copy link
Contributor Author

kpcyrd commented Mar 31, 2018

@mitsuhiko yes, works nicely. If we print 2 lines, one is a very long log line and the 2nd one is the progress bar, the terminal treats it as 3 lines (assuming one wrap), while indicatif has 2 lines recorded. Without the orphan logic it would try to clear the last two lines. This would remove the log line after the wrap and the progress bar. Since we set orphan_lines to 1, it would only clear one line, which is the progress bar.

@mitsuhiko mitsuhiko merged commit 950091d into console-rs:master Apr 1, 2018
@mitsuhiko
Copy link
Collaborator

Thanks. Merged. Will need to fix the appveyor stuff before I release this.

@kpcyrd kpcyrd deleted the println branch April 1, 2018 16:04
@bomgar
Copy link

bomgar commented Nov 20, 2018

This is an awesome feature. Is this going to be released at some point?

@bomgar
Copy link

bomgar commented Nov 23, 2018

I integrated this with my application. It does not seem to work with MultiProgress.

Is that something that can be added in an easy way? I might try to contribute here but I need some pointers.

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 this pull request may close these issues.

None yet

3 participants