forked from cargo-lambda/cargo-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.rs
46 lines (42 loc) · 1.18 KB
/
progress.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use atty::is;
use indicatif::{ProgressBar, ProgressStyle};
pub(crate) struct Progress {
bar: Option<ProgressBar>,
}
impl Progress {
pub fn start(msg: impl ToString) -> Progress {
let bar = if is(atty::Stream::Stdout) {
Some(show_progress(msg))
} else {
println!("▹▹▹▹▹ {}", msg.to_string());
None
};
Progress { bar }
}
pub fn finish(&self, msg: &str) {
if let Some(bar) = &self.bar {
bar.finish_with_message(msg.to_string());
} else {
println!("▪▪▪▪▪ {}", msg);
}
}
}
fn show_progress(msg: impl ToString) -> ProgressBar {
let pb = ProgressBar::new_spinner();
pb.enable_steady_tick(120);
pb.set_style(
ProgressStyle::default_spinner()
.template("{spinner:.blue} {msg}")
.tick_strings(&[
"▹▹▹▹▹",
"▸▹▹▹▹",
"▹▸▹▹▹",
"▹▹▸▹▹",
"▹▹▹▸▹",
"▹▹▹▹▸",
"▪▪▪▪▪",
]),
);
pb.set_message(msg.to_string());
pb
}