use console::style;
use indicatif::{ProgressBar, ProgressStyle};
pub struct ProgressReporter {
bar: ProgressBar,
}
impl ProgressReporter {
pub fn new() -> Self {
let bar = ProgressBar::new(0);
let style = ProgressStyle::default_bar()
.template(&format!(
"{} [{{bar:40.cyan/blue}}] {{pos}}/{{len}} files ({{msg}})",
style(" Shredding").green().bold()
))
.unwrap_or_else(|_| ProgressStyle::default_bar());
bar.set_style(style.progress_chars("#>-"));
Self { bar }
}
pub fn start_files(&self, total: u64) {
self.bar.set_length(total);
self.bar.set_message("processing...");
}
pub fn inc_file_complete(&self) {
self.bar.inc(1);
}
pub fn finish(&self) {
if !self.bar.is_finished() {
self.bar.set_position(self.bar.length().unwrap_or(0));
self.bar.finish_and_clear();
}
}
}
impl Default for ProgressReporter {
fn default() -> Self {
Self::new()
}
}