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<'a, R, E>(
mut closure: ProgressBarOp<'a, 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(|e| error(e))?;
let cb = Box::new(move || {
pb.update(1);
});
let result = closure(cb);
print!("\n");
return result;
}