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 10 months ago
commit a78f968834dc74be8f1a5e20bd95ee6c415e8521
parent 54fd8c40a0b64e061d0ec4f32b9471b36ec11ee0
1 file changed +33 -1
modified crates/radicle-term/src/io.rs
@@ -64,6 +64,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)*));
@@ -87,7 +111,15 @@ pub use success;
pub use tip;

pub fn success_args<W: io::Write>(w: &mut W, args: fmt::Arguments) {
-
    writeln!(w, "{} {args}", Paint::green("✓")).ok();
+
    writeln!(w, "{} {args}", SUCCESS_PREFIX).ok();
+
}
+

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

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

pub fn tip_args(args: fmt::Arguments) {