Skip to content

Commit 2b8aff7

Browse files
committed
feat: v8.0.0
1 parent 55a0ee8 commit 2b8aff7

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "color-output"
3-
version = "7.2.14"
3+
version = "8.0.0"
44
readme = "README.md"
55
edition = "2024"
66
authors = ["root@ltpp.vip"]

src/macro/cfg.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ fn test_proc_macro_multiple() {
5353
fn test_print_type() {
5454
use crate::*;
5555
let msg: &str = "1\n2\n3\r\n4";
56-
println_success!(msg);
56+
println_success!("{msg}");
5757
println!("==========");
58-
println_warning!(msg);
58+
println_warning!("{msg}");
5959
println!("==========");
60-
println_error!(msg);
60+
println_error!("{msg}");
6161
println!("==========");
6262
let msg: &str = "1234";
63-
println_success!(msg, msg);
63+
println_success!("{msg}{msg}");
6464
println!("==========");
65-
println_warning!(msg, msg);
65+
println_warning!("{msg}{msg}");
6666
println!("==========");
67-
println_error!(msg, msg);
67+
println_error!("{msg}{msg}");
6868
println!("==========");
6969
}

src/macro/macro.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
2525
macro_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]
5860
macro_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]
6673
macro_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]
7486
macro_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

Comments
 (0)