aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-core
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-09 12:15:21 +0900
committernsfisis <nsfisis@gmail.com>2026-05-09 12:15:53 +0900
commitf18c18cd15f180b5067069ec6f10530515715f3d (patch)
tree85ea3d3f10da9b32359dc3797fc7e6d262ae6752 /crates/mozart-core
parentf0192390ae1d89981f59395307e885a595f86eef (diff)
downloadphp-mozart-f18c18cd15f180b5067069ec6f10530515715f3d.tar.gz
php-mozart-f18c18cd15f180b5067069ec6f10530515715f3d.tar.zst
php-mozart-f18c18cd15f180b5067069ec6f10530515715f3d.zip
refactor(console): accept format args directly in console_writeln! macros
Eliminate the nested &console_format!(...) boilerplate at every call site by teaching console_writeln!, console_write!, console_writeln_error!, and console_write_error! to accept a format literal + variadic args directly, matching the println!/eprintln! ergonomics. Propagate the format string span into generated code so rustc errors point to the right location. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-core')
-rw-r--r--crates/mozart-core/src/console.rs56
1 files changed, 40 insertions, 16 deletions
diff --git a/crates/mozart-core/src/console.rs b/crates/mozart-core/src/console.rs
index e0c224f..e036b11 100644
--- a/crates/mozart-core/src/console.rs
+++ b/crates/mozart-core/src/console.rs
@@ -294,12 +294,18 @@ impl Console {
/// ref: \Composer\IO\IOInterface::write()
#[macro_export]
macro_rules! console_writeln {
- ($console:expr, $msg:expr $(,)?) => {
- $crate::console_writeln!($console, $msg, $crate::console::Verbosity::Normal)
+ ($console:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,)
};
- ($console:expr, $msg:expr, $verbosity:expr $(,)?) => {
+ ($console:expr, $fmt:literal, $($arg:tt)*) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*)
+ };
+ ($console:expr, $verbosity:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,)
+ };
+ ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => {
if ($console).verbosity >= $verbosity {
- println!("{}", $msg);
+ ::std::println!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*));
}
};
}
@@ -309,12 +315,18 @@ macro_rules! console_writeln {
/// ref: \Composer\IO\IOInterface::write()
#[macro_export]
macro_rules! console_write {
- ($console:expr, $msg:expr $(,)?) => {
- $crate::console_write!($console, $msg, $crate::console::Verbosity::Normal)
+ ($console:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,)
+ };
+ ($console:expr, $fmt:literal, $($arg:tt)*) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*)
+ };
+ ($console:expr, $verbosity:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,)
};
- ($console:expr, $msg:expr, $verbosity:expr $(,)?) => {
+ ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => {
if ($console).verbosity >= $verbosity {
- print!("{}", $msg);
+ ::std::print!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*));
}
};
}
@@ -324,12 +336,18 @@ macro_rules! console_write {
/// ref: \Composer\IO\IOInterface::writeError()
#[macro_export]
macro_rules! console_writeln_error {
- ($console:expr, $msg:expr $(,)?) => {
- $crate::console_writeln_error!($console, $msg, $crate::console::Verbosity::Normal)
+ ($console:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,)
};
- ($console:expr, $msg:expr, $verbosity:expr $(,)?) => {
+ ($console:expr, $fmt:literal, $($arg:tt)*) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*)
+ };
+ ($console:expr, $verbosity:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,)
+ };
+ ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => {
if ($console).verbosity >= $verbosity {
- eprintln!("{}", $msg);
+ ::std::eprintln!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*));
}
};
}
@@ -339,12 +357,18 @@ macro_rules! console_writeln_error {
/// ref: \Composer\IO\IOInterface::writeError()
#[macro_export]
macro_rules! console_write_error {
- ($console:expr, $msg:expr $(,)?) => {
- $crate::console_write_error!($console, $msg, $crate::console::Verbosity::Normal)
+ ($console:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,)
+ };
+ ($console:expr, $fmt:literal, $($arg:tt)*) => {
+ $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*)
+ };
+ ($console:expr, $verbosity:expr, $fmt:literal) => {
+ $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,)
};
- ($console:expr, $msg:expr, $verbosity:expr $(,)?) => {
+ ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => {
if ($console).verbosity >= $verbosity {
- eprint!("{}", $msg);
+ ::std::eprint!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*));
}
};
}