use indicatif::{ProgressBar, ProgressStyle};
use std::time::Duration;
pub struct Spinner {
bar: ProgressBar,
}
impl Spinner {
pub fn new(message: &str) -> Self {
let bar = ProgressBar::new_spinner();
bar.set_style(
ProgressStyle::default_spinner()
.tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")
.template("{spinner:.cyan} {msg}")
.expect("Invalid spinner template"),
);
bar.set_message(message.to_string());
bar.enable_steady_tick(Duration::from_millis(80));
Self { bar }
}
pub fn set_message(&self, message: &str) {
self.bar.set_message(message.to_string());
}
pub fn finish_with_message(&self, message: &str) {
self.bar.finish_with_message(message.to_string());
}
pub fn finish_and_clear(&self) {
self.bar.finish_and_clear();
}
}
impl Drop for Spinner {
fn drop(&mut self) {
self.bar.finish_and_clear();
}
}