Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rover_std: introduce new print macros #2090

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/rover-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod fs;
mod style;
mod url;

pub mod print;
pub mod prompt;
pub use error::RoverStdError;
pub use fs::Fs;
Expand Down
35 changes: 35 additions & 0 deletions crates/rover-std/src/print.rs
Original file line number Diff line number Diff line change
@@ -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)*);
}};
}
4 changes: 3 additions & 1 deletion crates/rover-std/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
Loading