devalang_core/utils/
spinner.rs1#[cfg(feature = "cli")]
2use indicatif::{ProgressBar, ProgressStyle};
3use std::time::Duration;
4
5#[cfg(feature = "cli")]
6pub fn with_spinner<T, F>(start_msg: &str, f: F) -> ProgressBar
7where
8 F: FnOnce() -> T,
9{
10 let spinner = ProgressBar::new_spinner();
11 spinner.set_style(
12 ProgressStyle::with_template("{spinner:.green} {msg}")
13 .unwrap()
14 .tick_strings(&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]),
15 );
16 spinner.set_message(start_msg.to_string());
17 spinner.enable_steady_tick(Duration::from_millis(80));
18
19 let _ = f();
20
21 spinner
22}