aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-core/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-06 03:38:32 +0900
committernsfisis <nsfisis@gmail.com>2026-05-06 04:05:13 +0900
commitbf96f8292c0e9818c8b5fc8713ca7506e4338a49 (patch)
tree61ddecc119ee0ae344eabdb9c0f784cdb3461a44 /crates/mozart-core/src
parentb97e34358be5df05a3db9f5f3ef1502eaa94b1c0 (diff)
downloadphp-mozart-bf96f8292c0e9818c8b5fc8713ca7506e4338a49.tar.gz
php-mozart-bf96f8292c0e9818c8b5fc8713ca7506e4338a49.tar.zst
php-mozart-bf96f8292c0e9818c8b5fc8713ca7506e4338a49.zip
refactor(console): add write macros and migrate commands to use them
Diffstat (limited to 'crates/mozart-core/src')
-rw-r--r--crates/mozart-core/src/console.rs60
1 files changed, 60 insertions, 0 deletions
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
// ---------------------------------------------------------------------------