vdev/
macros.rs

1macro_rules! fatal {
2    ($($arg:tt)*) => {{
3        use owo_colors::OwoColorize;
4        eprintln!(
5            "{}",
6            format!($($arg)*)
7                .if_supports_color(owo_colors::Stream::Stderr, |text| text.bright_red())
8        );
9        std::process::exit(1);
10    }};
11}
12
13macro_rules! define_display_macro {
14    // https://github.com/rust-lang/rust/issues/35853#issuecomment-415993963
15    // https://github.com/rust-lang/rust/issues/83527#issuecomment-1281176235
16    ($name:ident, $level:ident, $style:ident, $d:tt) => (
17        #[allow(unused_macros)]
18        macro_rules! $name {
19            ($d($d arg:tt)*) => {{
20                use owo_colors::OwoColorize;
21                if log::Level::$level <= *$crate::app::verbosity() {
22                    eprintln!(
23                        "{}",
24                        format!($d($d arg)*)
25                            .if_supports_color(owo_colors::Stream::Stderr, |text| text.$style())
26                    );
27                }
28            }};
29        }
30    );
31}
32
33define_display_macro!(trace, Trace, underline, $);
34define_display_macro!(debug, Debug, italic, $);
35define_display_macro!(info, Info, bold, $);
36define_display_macro!(success, Info, bright_cyan, $);
37define_display_macro!(waiting, Info, bright_magenta, $);
38define_display_macro!(warn, Warn, bright_yellow, $);
39define_display_macro!(error, Error, bright_red, $);