use kdam::Bar;
use kdam::BarExt;
pub type ProgressBarOp<'a, R, E> = Box<dyn FnMut(Box<dyn FnMut()>) -> Result<R, E> + 'a>;
pub fn with_progress_bar<R, E>(
mut closure: ProgressBarOp<'_, R, E>,
error: Box<dyn Fn(String) -> E>,
count: usize,
message: String,
animation: String,
) -> Result<R, E> {
let mut pb = Bar::builder()
.total(count)
.animation(animation.as_str())
.desc(message)
.build()
.map_err(error)?;
let cb = Box::new(move || {
let _ = pb.update(1);
});
let result = closure(cb);
eprintln!();
result
}