@@ -18,12 +18,12 @@ macro_rules! output_macro {
1818///
1919/// - `ColorType` - Text color
2020/// - `ColorType` - Background color
21- /// - `&str` - One or more message strings to print
21+ /// - Format string and arguments (same as `format!` macro)
2222///
2323/// Used by the success/warning/error printing macros to avoid code duplication.
2424#[ macro_export]
2525macro_rules! __print_message_common {
26- ( $color: expr, $bg_color: expr, $( $data : expr ) , * ) => { {
26+ ( $color: expr, $bg_color: expr, $( $arg : tt ) * ) => { {
2727 use $crate:: * ;
2828 let binding: String = format!( "[{}]" , time( ) ) ;
2929 let mut time_output_builder: OutputBuilder <' _> = OutputBuilder :: new( ) ;
@@ -34,10 +34,7 @@ macro_rules! __print_message_common {
3434 . bg_color( $bg_color)
3535 . build( ) ;
3636 let mut text_output_builder: OutputBuilder <' _> = OutputBuilder :: new( ) ;
37- let mut text: String = String :: new( ) ;
38- $(
39- text. push_str( & $data. to_string( ) ) ;
40- ) *
37+ let text: String = format!( $( $arg) * ) ;
4138 let mut lines_iter = text. lines( ) . peekable( ) ;
4239 while let Some ( line) = lines_iter. next( ) {
4340 let mut output_list_builder = OutputListBuilder :: new( ) ;
@@ -54,25 +51,40 @@ macro_rules! __print_message_common {
5451}
5552
5653/// Prints a success message with green background and white text.
54+ ///
55+ /// Supports format string syntax like `format!` macro:
56+ /// - `println_success!("Hello")` - Simple string
57+ /// - `println_success!("Hello {}", name)` - Positional arguments
58+ /// - `println_success!("Hello {name}")` - Named arguments (Rust 1.58+)
5759#[ macro_export]
5860macro_rules! println_success {
59- ( $( $data : expr ) , * ) => {
60- $crate:: __print_message_common!( ColorType :: Use ( Color :: White ) , ColorType :: Use ( Color :: Green ) , $( $data ) , * ) ;
61+ ( $( $arg : tt ) * ) => {
62+ $crate:: __print_message_common!( ColorType :: Use ( Color :: White ) , ColorType :: Use ( Color :: Green ) , $( $arg ) * ) ;
6163 } ;
6264}
6365
6466/// Prints a warning message with yellow background and white text.
67+ ///
68+ /// Supports format string syntax like `format!` macro:
69+ /// - `println_warning!("Warning")` - Simple string
70+ /// - `println_warning!("Warning: {}", error)` - Positional arguments
71+ /// - `println_warning!("Warning: {error}")` - Named arguments (Rust 1.58+)
6572#[ macro_export]
6673macro_rules! println_warning {
67- ( $( $data : expr ) , * ) => {
68- $crate:: __print_message_common!( ColorType :: Use ( Color :: White ) , ColorType :: Use ( Color :: Yellow ) , $( $data ) , * ) ;
74+ ( $( $arg : tt ) * ) => {
75+ $crate:: __print_message_common!( ColorType :: Use ( Color :: White ) , ColorType :: Use ( Color :: Yellow ) , $( $arg ) * ) ;
6976 } ;
7077}
7178
7279/// Prints an error message with red background and white text.
80+ ///
81+ /// Supports format string syntax like `format!` macro:
82+ /// - `println_error!("Error")` - Simple string
83+ /// - `println_error!("Error: {}", message)` - Positional arguments
84+ /// - `println_error!("Error: {message}")` - Named arguments (Rust 1.58+)
7385#[ macro_export]
7486macro_rules! println_error {
75- ( $( $data : expr ) , * ) => {
76- $crate:: __print_message_common!( ColorType :: Use ( Color :: White ) , ColorType :: Use ( Color :: Red ) , $( $data ) , * ) ;
87+ ( $( $arg : tt ) * ) => {
88+ $crate:: __print_message_common!( ColorType :: Use ( Color :: White ) , ColorType :: Use ( Color :: Red ) , $( $arg ) * ) ;
7789 } ;
7890}
0 commit comments