Skip to main content

sys_shred/ui/
styles.rs

1//! # Terminal UI Styles
2//!
3//! Provides standardized styling for terminal output, mimicking the
4//! aesthetic of the Rust compiler (rustc).
5
6use console::Style;
7use std::fmt;
8
9/// Predefined styles for consistent UI labels.
10pub struct UiStyle {
11    /// Style for success labels (Green Bold).
12    pub success: Style,
13    /// Style for warning labels (Yellow Bold).
14    pub warning: Style,
15    /// Style for error labels (Red Bold).
16    pub error: Style,
17    /// Style for info labels (Cyan Bold).
18    pub info: Style,
19    /// Standard bold text.
20    pub bold: Style,
21}
22
23impl UiStyle {
24    /// Creates a new `UiStyle` with default terminal colors.
25    pub fn new() -> Self {
26        Self {
27            success: Style::new().green().bold(),
28            warning: Style::new().yellow().bold(),
29            error: Style::new().red().bold(),
30            info: Style::new().cyan().bold(),
31            bold: Style::new().bold(),
32        }
33    }
34}
35
36impl Default for UiStyle {
37    fn default() -> Self {
38        Self::new()
39    }
40}
41
42impl UiStyle {
43    /// Prints a styled action label followed by text.
44    /// Example: "    Shredding file.txt"
45    pub fn action<T: fmt::Display>(&self, label: &str, message: T) {
46        println!("{:>12} {}", self.success.apply_to(label), message);
47    }
48
49    /// Prints a styled info label followed by text.
50    pub fn info<T: fmt::Display>(&self, label: &str, message: T) {
51        println!("{:>12} {}", self.info.apply_to(label), message);
52    }
53
54    /// Prints a styled warning.
55    pub fn warn<T: fmt::Display>(&self, message: T) {
56        eprintln!("{:>12} {}", self.warning.apply_to("Warning"), message);
57    }
58
59    /// Prints a styled error.
60    pub fn error<T: fmt::Display>(&self, message: T) {
61        eprintln!("{:>12} {}", self.error.apply_to("Error"), message);
62    }
63
64    /// Prints a "Finished" status.
65    pub fn finished<T: fmt::Display>(&self, message: T) {
66        println!("{:>12} {}", self.success.apply_to("Finished"), message);
67    }
68}
69
70lazy_static::lazy_static! {
71    /// Global instance of the UI styling engine.
72    pub static ref UI: UiStyle = UiStyle::new();
73}