From bf96f8292c0e9818c8b5fc8713ca7506e4338a49 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 6 May 2026 03:38:32 +0900 Subject: refactor(console): add write macros and migrate commands to use them --- crates/mozart-core/src/console.rs | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'crates/mozart-core') diff --git a/crates/mozart-core/src/console.rs b/crates/mozart-core/src/console.rs index fb7c9b9..734074e 100644 --- a/crates/mozart-core/src/console.rs +++ b/crates/mozart-core/src/console.rs @@ -259,6 +259,66 @@ impl Console { } } +/// Writes a message to the output. +/// +/// 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, $msg:expr, $verbosity:expr $(,)?) => { + if ($console).verbosity >= $verbosity { + println!("{}", $msg); + } + }; +} + +/// Writes a message to the output without newline. +/// +/// 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, $msg:expr, $verbosity:expr $(,)?) => { + if ($console).verbosity >= $verbosity { + print!("{}", $msg); + } + }; +} + +/// Writes a message to the error output. +/// +/// 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, $msg:expr, $verbosity:expr $(,)?) => { + if ($console).verbosity >= $verbosity { + eprintln!("{}", $msg); + } + }; +} + +/// Writes a message to the error output without newline. +/// +/// 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, $msg:expr, $verbosity:expr $(,)?) => { + if ($console).verbosity >= $verbosity { + eprint!("{}", $msg); + } + }; +} + // --------------------------------------------------------------------------- // Tests // --------------------------------------------------------------------------- -- cgit v1.3.1