color_output/macro/
macro.rs

1/// Macro for outputting colored text to the terminal.
2///
3/// # Arguments
4///
5/// - `Output` or `OutputBuilder` - One or more output instances to execute
6#[macro_export]
7macro_rules! output_macro {
8    ($($output:expr),*) => {
9        $(
10            $output.output();
11        )*
12    };
13}
14
15/// Internal macro for handling common message printing logic.
16///
17/// # Arguments
18///
19/// - `ColorType` - Text color
20/// - `ColorType` - Background color
21/// - `&str` - One or more message strings to print
22///
23/// Used by the success/warning/error printing macros to avoid code duplication.
24#[macro_export]
25macro_rules! __print_message_common {
26    ($color:expr, $bg_color:expr, $($data:expr),*) => {{
27        use crate::*;
28        let binding: String = format!("[{}]", time());
29        let mut time_output_builder: OutputBuilder<'_> = OutputBuilder::new();
30        let time_output: Output<'_> = time_output_builder
31            .text(&binding)
32            .blod(true)
33            .color($color)
34            .bg_color($bg_color)
35            .build();
36        let mut text_output_builder: OutputBuilder<'_> = OutputBuilder::new();
37        let mut text: String = String::new();
38        $(
39            text.push_str(&$data.to_string());
40        )*
41        let mut lines_iter = text.lines().peekable();
42        while let Some(line) = lines_iter.next() {
43            let mut output_list_builder = OutputListBuilder::new();
44            output_list_builder.add(time_output.clone());
45            let text_output: Output<'_> = text_output_builder
46                .text(&line)
47                .blod(true)
48                .endl(true)
49                .build();
50            output_list_builder.add(text_output);
51            output_list_builder.run();
52        }
53    }};
54}
55
56/// Prints a success message with green background and white text.
57#[macro_export]
58macro_rules! println_success {
59    ($($data:expr),*) => {
60        crate::__print_message_common!(ColorType::Use(Color::White), ColorType::Use(Color::Green), $($data),*);
61    };
62}
63
64/// Prints a warning message with yellow background and white text.
65#[macro_export]
66macro_rules! println_warning {
67    ($($data:expr),*) => {
68        crate::__print_message_common!(ColorType::Use(Color::White), ColorType::Use(Color::Yellow), $($data),*);
69    };
70}
71
72/// Prints an error message with red background and white text.
73#[macro_export]
74macro_rules! println_error {
75    ($($data:expr),*) => {
76        crate::__print_message_common!(ColorType::Use(Color::White), ColorType::Use(Color::Red), $($data),*);
77    };
78}