diff --git a/crates/rover-std/src/lib.rs b/crates/rover-std/src/lib.rs index 0150ea44d..932ed4d2b 100644 --- a/crates/rover-std/src/lib.rs +++ b/crates/rover-std/src/lib.rs @@ -3,6 +3,7 @@ mod fs; mod style; mod url; +pub mod print; pub mod prompt; pub use error::RoverStdError; pub use fs::Fs; diff --git a/crates/rover-std/src/print.rs b/crates/rover-std/src/print.rs new file mode 100644 index 000000000..c36426d4e --- /dev/null +++ b/crates/rover-std/src/print.rs @@ -0,0 +1,35 @@ +/// Prints to the standard output, with a newline. +/// +/// Equivalent to the [`println!`] macro except that an info prefix is +/// printed before the message. +#[macro_export] +macro_rules! infoln { + ($($t:tt)*) => {{ + print!("{} ", $crate::Style::InfoPrefix.paint("==>")); + println!($($t)*); + }}; +} + +/// Prints to the standard error, with a newline. +/// +/// Equivalent to the [`eprintln!`] macro except that a warning prefix is +/// printed before the message. +#[macro_export] +macro_rules! warnln { + ($($t:tt)*) => {{ + eprint!("{}: ", $crate::Style::WarningPrefix.paint("warning")); + eprintln!($($t)*); + }}; +} + +/// Prints to the standard error, with a newline. +/// +/// Equivalent to the [`eprintln!`] macro except that an error prefix is +/// printed before the message. +#[macro_export] +macro_rules! errln { + ($($t:tt)*) => {{ + eprint!("{}: ", $crate::Style::ErrorPrefix.paint("error")); + eprintln!($($t)*); + }}; +} diff --git a/crates/rover-std/src/style.rs b/crates/rover-std/src/style.rs index 02ab4bc3d..d5e35da7e 100644 --- a/crates/rover-std/src/style.rs +++ b/crates/rover-std/src/style.rs @@ -7,6 +7,7 @@ pub enum Style { Path, // File paths Pending, HintPrefix, // "HINT:" text + InfoPrefix, // "==>": text WarningPrefix, // "WARN:" text ErrorPrefix, // "ERROR:", "error:", and "error[code]:" text Heading, @@ -35,7 +36,8 @@ impl Style { Style::Failure => style(message_ref).red(), Style::WhoAmIKey | Style::NewOperationCount => style(message_ref).green(), Style::HintPrefix => style(message_ref).cyan().bold(), - Style::WarningPrefix => style(message_ref).red(), + Style::InfoPrefix => style(message_ref).blue().bold(), + Style::WarningPrefix => style(message_ref).yellow(), Style::ErrorPrefix => style(message_ref).red().bold(), Style::Variant => style(message_ref).white().bold(), Style::Path | Style::Heading => style(message_ref).bold(),