mistralrs_core/utils/
progress.rsuse indicatif::{ProgressBar, ProgressBarIter, ProgressIterator, ProgressStyle};
use tqdm::Iter;
pub trait IterWithProgress<'a, T>: Iterator<Item = T> + 'a {
fn with_progress(self, is_silent: bool) -> Box<dyn Iterator<Item = T> + 'a>
where
Self: Sized,
{
if is_silent {
Box::new(self)
} else {
Box::new(self.tqdm())
}
}
}
impl<'a, T: Iterator + 'a> IterWithProgress<'a, T::Item> for T {}
pub struct NiceProgressBar<T: ExactSizeIterator, const COLOR: char = 'b'>(pub T, pub &'static str);
impl<T: ExactSizeIterator, const COLOR: char> IntoIterator for NiceProgressBar<T, COLOR> {
type IntoIter = ProgressBarIter<T>;
type Item = T::Item;
fn into_iter(self) -> Self::IntoIter {
let color = match COLOR {
'b' => "blue",
'g' => "green",
'r' => "red",
other => panic!("Color char `{other}` not supported"),
};
let bar = ProgressBar::new(self.0.len() as u64);
bar.set_style(
ProgressStyle::default_bar()
.template(&format!(
"{}: [{{elapsed_precise}}] [{{bar:40.{color}/{color}}}] {{pos}}/{{len}} ({{eta}})",
self.1
))
.unwrap()
.progress_chars("#>-"),
);
self.0.progress_with(bar)
}
}