//! Shared progress-bar styling for the utility binaries. Centralised so every //! `cargo run --bin ...` tool gets the same look and feel. use indicatif::{ProgressBar, ProgressStyle}; const DETERMINATE_TEMPLATE: &str = "{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] \ {human_pos}/{human_len} ({percent}%) {per_sec} eta {eta} {msg}"; const SPINNER_TEMPLATE: &str = "{spinner:.green} [{elapsed_precise}] {human_pos} {per_sec} {msg}"; /// Determinate progress bar used when the total work is known up front. pub fn determinate(total: u64, message: impl Into) -> ProgressBar { let pb = ProgressBar::new(total); pb.set_style( ProgressStyle::with_template(DETERMINATE_TEMPLATE) .expect("hard-coded template parses") .progress_chars("=> "), ); pb.set_message(message.into()); pb } /// Spinner used for open-ended work (e.g. paginated DB scans that loop until /// empty). Throughput is shown via `{per_sec}`; tick at a steady cadence so /// it animates even when work is bursty. pub fn spinner(message: impl Into) -> ProgressBar { let pb = ProgressBar::new_spinner(); pb.set_style( ProgressStyle::with_template(SPINNER_TEMPLATE).expect("hard-coded template parses"), ); pb.set_message(message.into()); pb.enable_steady_tick(std::time::Duration::from_millis(120)); pb }