1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::time::Duration;

use indicatif::{ProgressBar, ProgressStyle};

use crate::error::Error;

pub struct SpinnerHelper;

const TICK_TIME: u64 = 120;

impl SpinnerHelper {
    pub fn create(message: String) -> Result<ProgressBar, Error> {
        let spinner = ProgressBar::new_spinner();
        spinner.enable_steady_tick(Duration::from_secs(TICK_TIME));
        spinner.set_style(
            ProgressStyle::default_spinner()
                // For more spinners check out the cli-spinners project:
                // https://github.com/sindresorhus/cli-spinners/blob/master/spinners.json
                .tick_strings(&[
                    "□ □ □ □ □",
                    "■ □ □ □ □",
                    "□ ■ □ □ □",
                    "□ □ ■ □ □",
                    "□ □ □ ■ □",
                    "□ □ □ □ ■",
                    "■ ■ ■ ■ ■",
                ])
                .template("{spinner:.blue} {msg}")?,
        );
        spinner.set_message(message);

        Ok(spinner)
    }
}