Skip to main content

walker_common/progress/
indicatif.rs

1use indicatif::{MultiProgress, ProgressStyle};
2
3impl super::Progress for MultiProgress {
4    type Instance = indicatif::ProgressBar;
5
6    fn start(&self, work: usize) -> Self::Instance {
7        let work = work.try_into().unwrap_or(u64::MAX);
8        let bar = indicatif::ProgressBar::new(work);
9        bar.set_style(
10            ProgressStyle::default_bar()
11                .template("{msg:<20} {wide_bar} {pos}/{len} ({eta})")
12                .expect("template must parse"),
13        );
14
15        self.add(bar)
16    }
17
18    fn println(&self, message: &str) {
19        let _ = MultiProgress::println(self, message);
20    }
21}
22
23impl super::ProgressBar for indicatif::ProgressBar {
24    async fn increment(&mut self, work: usize) {
25        indicatif::ProgressBar::inc(self, work as u64)
26    }
27
28    async fn finish(self) {
29        indicatif::ProgressBar::finish_and_clear(&self)
30    }
31
32    async fn set_message(&mut self, msg: String) {
33        indicatif::ProgressBar::set_message(self, msg)
34    }
35}