Skip to main content

fsmon/common/
color.rs

1// ANSI color codes for terminal output
2
3/// Yellow color for labels (DEBUG, WARNING, etc.)
4pub const YELLOW: &str = "\x1b[33m";
5/// Green color for commands and INFO
6pub const GREEN: &str = "\x1b[32m";
7/// Red color for ERROR
8pub const RED: &str = "\x1b[31m";
9/// Reset color to default
10pub const RESET: &str = "\x1b[0m";
11
12// ---- Const macros for use in const fn ----
13
14/// Wrap text with yellow color (for use in const context)
15#[macro_export]
16macro_rules! yellow {
17    ($text:expr) => {
18        concat!("\x1b[33m", $text, "\x1b[0m")
19    };
20}
21
22/// Wrap text with green color (for use in const context)
23#[macro_export]
24macro_rules! green {
25    ($text:expr) => {
26        concat!("\x1b[32m", $text, "\x1b[0m")
27    };
28}
29
30// ---- Colored log macros (crate-level export) ----
31
32/// Colored debug output: [DEBUG] in yellow
33#[macro_export]
34macro_rules! debug_log {
35    ($debug:expr, $($arg:tt)*) => {
36        if $debug { eprintln!("{}[DEBUG]{} {}", $crate::common::color::YELLOW, $crate::common::color::RESET, format!($($arg)*)); }
37    };
38}
39
40/// Colored info output: [INFO] in green
41#[macro_export]
42macro_rules! info_log {
43    ($($arg:tt)*) => {
44        eprintln!("{}[INFO]{}  {}", $crate::common::color::GREEN, $crate::common::color::RESET, format!($($arg)*));
45    };
46}
47
48/// Colored warning output: [WARNING] in yellow
49#[macro_export]
50macro_rules! warning_log {
51    ($($arg:tt)*) => {
52        eprintln!("{}[WARNING]{} {}", $crate::common::color::YELLOW, $crate::common::color::RESET, format!($($arg)*));
53    };
54}
55
56/// Colored error output: [ERROR] in red
57#[macro_export]
58macro_rules! error_log {
59    ($($arg:tt)*) => {
60        eprintln!("{}[ERROR]{}  {}", $crate::common::color::RED, $crate::common::color::RESET, format!($($arg)*));
61    };
62}