#[cfg(any(feature = "tiffwrite", feature = "movie"))]
pub(crate) mod progress {
use console::Term;
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressState, ProgressStyle};
use std::time::Duration;
pub fn get_bar(count: Option<usize>, message: Option<String>) -> ProgressBar {
let style = ProgressStyle::with_template(
"{spinner:.green} {msg} {percent}% [{wide_bar:.green/lime}] {pos:>7}/{len:7} [{elapsed}/{eta}, {rate}]",
)
.expect("could not build progress bar style")
.with_key("rate", |state: &ProgressState, w: &mut dyn std::fmt::Write| {
if state.per_sec() < 1.0 {
write!(w, "{:>4.2} s", 1.0 / state.per_sec()).expect("could not write to progress bar");
} else {
write!(w, "{:>4.2}/s", state.per_sec()).expect("could not write to progress bar");
}
})
.progress_chars("#>-");
let bar = ProgressBar::with_draw_target(
count.map(|i| i as u64),
ProgressDrawTarget::term_like_with_hz(Box::new(Term::buffered_stdout()), 20),
)
.with_style(style);
if let Some(message) = message {
bar.set_message(message);
}
bar.enable_steady_tick(Duration::from_millis(100));
bar
}
}