Skip to main content

sys_shred/ui/
progress.rs

1//! # Terminal UI & Progress Feedback
2//!
3//! Provides interactive visual feedback to the user during long-running
4//! shredding operations using the `indicatif` crate.
5
6use indicatif::{ProgressBar, ProgressStyle};
7
8/// A high-level reporter for managing terminal progress visuals.
9pub struct ProgressReporter {
10    /// The primary progress bar handle.
11    bar: ProgressBar,
12}
13
14impl ProgressReporter {
15    /// Creates a new `ProgressReporter` instance.
16    pub fn new() -> Self {
17        let bar = ProgressBar::new(0);
18        let style = ProgressStyle::default_bar()
19            .template(
20                "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} files ({msg})",
21            )
22            .unwrap_or_else(|_| ProgressStyle::default_bar());
23        bar.set_style(style.progress_chars("#>-"));
24
25        Self { bar }
26    }
27
28    /// Initializes the progress bar with the total number of files.
29    pub fn start_files(&self, total: u64) {
30        self.bar.set_length(total);
31        self.bar.set_message("Shredding in progress...");
32    }
33
34    /// Increments the count of completed files.
35    pub fn inc_file_complete(&self) {
36        self.bar.inc(1);
37    }
38
39    /// Finalizes the progress reporting.
40    pub fn finish(&self) {
41        self.bar
42            .finish_with_message("All targets securely destroyed.");
43    }
44}
45
46impl Default for ProgressReporter {
47    fn default() -> Self {
48        Self::new()
49    }
50}