24 lines
575 B
Rust
24 lines
575 B
Rust
|
|
use std::{error::Error, future::Future};
|
||
|
|
use indicatif::ProgressBar;
|
||
|
|
|
||
|
|
pub async fn with_spinner<F, Fut, T>(
|
||
|
|
start_msg: &str,
|
||
|
|
finish_msg: &str,
|
||
|
|
f: F,
|
||
|
|
) -> Result<T, Box<dyn Error>>
|
||
|
|
where
|
||
|
|
F: FnOnce() -> Fut,
|
||
|
|
Fut: Future<Output = Result<T, Box<dyn Error>>>,
|
||
|
|
{
|
||
|
|
let pb = ProgressBar::new_spinner();
|
||
|
|
pb.set_message(start_msg.to_string());
|
||
|
|
pb.enable_steady_tick(std::time::Duration::from_millis(100));
|
||
|
|
|
||
|
|
let result = f().await;
|
||
|
|
|
||
|
|
pb.finish_and_clear();
|
||
|
|
println!("{} {}", dialoguer::console::style("✔").green(), finish_msg);
|
||
|
|
|
||
|
|
result
|
||
|
|
}
|