use crate::InteractionEnvironment; use indicatif::ProgressStyle; use l10n_embed::Localize; use std::sync::LazyLock; use std::time::Duration; static PROGRESS_TEMPLATE: LazyLock<ProgressStyle> = LazyLock::new(|| { ProgressStyle::with_template("{msg:<20} [{bar:50}] {pos}/{len} [{elapsed_precise}]") .unwrap() .progress_chars("=> ") }); pub struct ProgressBar { progress_bar: indicatif::ProgressBar, } impl<'environment> ProgressBar { pub fn new<L: Localize>( environment: &'environment InteractionEnvironment, message: L, length: u64, ) -> Self { let localized_text = message.localize_for(&environment.locale); let progress_bar = indicatif::ProgressBar::new(length) .with_style(PROGRESS_TEMPLATE.clone()) .with_message(localized_text); progress_bar.enable_steady_tick(Duration::from_millis(10)); Self { progress_bar: environment.progress_bars.add(progress_bar), } } pub fn increment(&self, delta: u64) { self.progress_bar.inc(delta); } pub fn finish(self) { self.progress_bar.finish(); } }