aboutsummaryrefslogtreecommitdiff
path: root/mingling_ci/src/progress.rs
blob: bd62ae14523a7451b4e4e34004f8699dcfd57893 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! Shared task progress bar.

use colored::Colorize;
use indicatif::{ProgressBar, ProgressStyle};

/// Creates a task progress bar with the CI's standard style.
///
/// `prefix` is the phase label shown before the bar, right-aligned to 12
/// columns (e.g. `Building`, `Clippy`, `Testing`). The caller sets the
/// initial message and drives the position.
pub(crate) fn task_progress_bar(len: usize, prefix: &str) -> ProgressBar {
    let padding = " ".repeat(12usize.saturating_sub(prefix.len()));
    let styled_prefix = format!("{padding}{}", prefix.bold().bright_cyan());
    let pb = ProgressBar::new(len as u64);
    pb.set_style(
        ProgressStyle::default_bar()
            .template(&format!(
                "{styled_prefix} [{{bar:28}}] {{pos}}/{{len}}: {{msg}}"
            ))
            .unwrap()
            .progress_chars("=> "),
    );
    pb
}