Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Add output macros for warnings and errors
Erik Kundt committed 9 months ago
commit 7e803f27a85af62dc56ad8147e1d969278eb1d05
parent 55cdd880bfee08124d5b6a38cc05036402c7ab6e
1 file changed +32 -0
modified crates/radicle-term/src/io.rs
@@ -69,6 +69,30 @@ macro_rules! success {
}

#[macro_export]
+
macro_rules! warning {
+
    // Pattern when a writer is provided.
+
    ($writer:expr; $($arg:tt)*) => ({
+
        $crate::io::warning_args($writer, format_args!($($arg)*));
+
    });
+
    // Pattern without writer.
+
    ($($arg:tt)*) => ({
+
        $crate::io::warning_args(&mut std::io::stdout(), format_args!($($arg)*));
+
    });
+
}
+

+
#[macro_export]
+
macro_rules! error {
+
    // Pattern when a writer is provided.
+
    ($writer:expr; $($arg:tt)*) => ({
+
        $crate::io::error_args($writer, format_args!($($arg)*));
+
    });
+
    // Pattern without writer.
+
    ($($arg:tt)*) => ({
+
        $crate::io::error_args(&mut std::io::stdout(), format_args!($($arg)*));
+
    });
+
}
+

+
#[macro_export]
macro_rules! tip {
    ($($arg:tt)*) => ({
        $crate::io::tip_args(format_args!($($arg)*));
@@ -95,6 +119,14 @@ pub fn success_args<W: io::Write>(w: &mut W, args: fmt::Arguments) {
    writeln!(w, "{PREFIX_SUCCESS} {args}").ok();
}

+
pub fn warning_args<W: io::Write>(w: &mut W, args: fmt::Arguments) {
+
    writeln!(w, "{PREFIX_WARNING} {args}").ok();
+
}
+

+
pub fn error_args<W: io::Write>(w: &mut W, args: fmt::Arguments) {
+
    writeln!(w, "{PREFIX_ERROR} {args}").ok();
+
}
+

pub fn tip_args(args: fmt::Arguments) {
    println!(
        "{} {}",