📄 src/progress.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14
use indicatif::{ProgressBar, ProgressStyle};

/// A single-line progress bar (elapsed time, bar, position/total, rate, ETA) in the
/// style used by Brush's CLI, for a fixed-size loop with `len` items counted in `unit`.
pub fn new(len: u64, unit: &str) -> ProgressBar {
  let template =
    format!("[{{elapsed_precise}}] {{bar:40.cyan/blue}} {{pos}}/{{len}} {unit} ({{per_sec}}, {{eta}} remaining)");
  ProgressBar::new(len).with_style(
    ProgressStyle::with_template(&template)
      .expect("valid indicatif template")
      .progress_chars("◍○○"),
  )
}