slf/
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
use std::{future::Future, time::Duration};

use anyhow::Result;
use indicatif::{ProgressBar, ProgressStyle};

pub async fn new<F, Fut, T>(callback: F) -> Result<T>
where
    F: FnOnce() -> Fut,
    Fut: Future<Output = Result<T>>,
{
    let spinner = ProgressBar::new_spinner();
    spinner.set_style(
        ProgressStyle::default_spinner()
            .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈")
            .template("{spinner} Generating commit message...")?,
    );
    spinner.enable_steady_tick(Duration::from_millis(120));

    let result = callback().await?;
    spinner.finish_and_clear();

    Ok(result)
}