1use indicatif::{ProgressBar, ProgressStyle};
2use std::time::Duration;
3
4pub struct Spinner {
8 progress_bar: ProgressBar,
9}
10
11impl Spinner {
12 #[allow(clippy::unwrap_used)]
14 pub fn new(message: &str) -> Self {
15 let progress_bar = ProgressBar::new_spinner();
16 progress_bar.set_style(
18 ProgressStyle::default_spinner()
19 .tick_strings(&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"])
20 .template("{spinner} {msg}")
21 .unwrap(),
22 );
23 progress_bar.set_message(message.to_string());
24 progress_bar.enable_steady_tick(Duration::from_millis(80));
25
26 Self { progress_bar }
27 }
28
29 pub fn stop(&self) {
31 self.progress_bar.finish_and_clear();
32 }
33}
34
35impl Drop for Spinner {
36 fn drop(&mut self) {
37 self.progress_bar.finish_and_clear();
38 }
39}