-
Notifications
You must be signed in to change notification settings - Fork 6
/
spinner.rs
32 lines (29 loc) · 1.05 KB
/
spinner.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
use std::{thread::sleep, time::Duration};
use demand::{Spinner, SpinnerStyle, Theme};
fn main() {
let custom_style = SpinnerStyle {
frames: vec![
" ", "- ", "-- ", "---", " --", " -", " ", " -", " --", "---", "-- ", "- ",
],
fps: Duration::from_millis(1000 / 10),
};
let dots = SpinnerStyle::dots();
let line = SpinnerStyle::line();
let charm = Theme::charm();
let catppuccin = Theme::catppuccin();
Spinner::new("Loading Data...")
.style(&custom_style)
.run(|s| {
sleep(Duration::from_secs(2));
let mut toggle = false;
for name in ["Files", "Data", "Your Soul"] {
let _ = s.title(format!("Loading {name}..."));
let _ = s.style(if toggle { &dots } else { &line });
let _ = s.theme(if toggle { &catppuccin } else { &charm });
toggle = !toggle;
sleep(Duration::from_secs(2));
}
})
.expect("error running spinner");
println!("Data loaded.");
}