Created
December 23, 2019 22:37
-
-
Save inv2004/127aff606d2d5bf5e8ab9197c7a9b71b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::time::Duration; | |
use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | |
fn main() { | |
let m = MultiProgress::new(); | |
let sty = ProgressStyle::default_bar() | |
.template("[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}") | |
.progress_chars("##-"); | |
let pb = m.add(ProgressBar::new(128)); | |
pb.set_style(sty.clone()); | |
let _ = thread::spawn(move || { | |
for i in 0..128 { | |
pb.set_message(&format!("item #{}", i + 1)); | |
pb.inc(1); | |
let mut v = Vec::new(); | |
for i in 0..100_000 { | |
v.push(i); | |
} | |
} | |
pb.finish_with_message("done"); | |
}); | |
let pb = m.add(ProgressBar::new(128)); | |
pb.set_style(sty.clone()); | |
let _ = thread::spawn(move || { | |
for _ in 0..3 { | |
pb.set_position(0); | |
for i in 0..128 { | |
pb.set_message(&format!("item #{}", i + 1)); | |
pb.inc(1); | |
let mut v = Vec::new(); | |
for i in 0..100_000 { | |
v.push(i); | |
} | |
} | |
} | |
pb.finish_with_message("done"); | |
}); | |
let pb = m.add(ProgressBar::new(1024)); | |
pb.set_style(sty.clone()); | |
let _ = thread::spawn(move || { | |
for i in 0..1024 { | |
pb.set_message(&format!("item #{}", i + 1)); | |
pb.inc(1); | |
let mut v = Vec::new(); | |
for i in 0..100_000 { | |
v.push(i); | |
} | |
} | |
pb.finish_with_message("done"); | |
}); | |
m.join_and_clear().unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment