hiro_system_kit/
macros.rs

1#[allow(unused_macros)]
2#[macro_export]
3macro_rules! green {
4    ($($arg:tt)*) => (
5        {
6            use atty::Stream;
7            use ansi_term::{Colour, Style};
8            if atty::is(Stream::Stdout) {
9                let colour = Colour::Green.bold();
10                format!(
11                    "{}",
12                    colour.paint($($arg)*)
13                )
14            } else {
15                format!(
16                    "{}",
17                    $($arg)*
18                )
19            }
20        }
21    )
22}
23
24#[allow(unused_macros)]
25#[macro_export]
26macro_rules! red {
27    ($($arg:tt)*) => (
28        {
29            use atty::Stream;
30            use ansi_term::{Colour, Style};
31            if atty::is(Stream::Stdout) {
32                let colour = Colour::Red.bold();
33                format!(
34                    "{}",
35                    colour.paint($($arg)*)
36                )
37            } else {
38                format!(
39                    "{}",
40                    $($arg)*
41                )
42            }
43        }
44    )
45}
46
47#[allow(unused_macros)]
48#[macro_export]
49macro_rules! yellow {
50    ($($arg:tt)*) => (
51        {
52            use atty::Stream;
53            use ansi_term::{Colour, Style};
54            if atty::is(Stream::Stdout) {
55                let colour = Colour::Yellow.bold();
56                format!(
57                    "{}",
58                    colour.paint($($arg)*)
59                )
60            } else {
61                format!(
62                    "{}",
63                    $($arg)*
64                )
65            }
66        }
67    )
68}
69
70#[allow(unused_macros)]
71#[macro_export]
72macro_rules! blue {
73    ($($arg:tt)*) => (
74        {
75            use atty::Stream;
76            use ansi_term::{Colour, Style};
77            if atty::is(Stream::Stdout) {
78                let colour = Colour::Cyan.bold();
79                format!(
80                    "{}",
81                    colour.paint($($arg)*)
82                )
83            } else {
84                format!(
85                    "{}",
86                    $($arg)*
87                )
88            }
89        }
90    )
91}
92
93#[allow(unused_macros)]
94#[macro_export]
95macro_rules! purple {
96    ($($arg:tt)*) => (
97        {
98            use atty::Stream;
99            use ansi_term::{Colour, Style};
100            if atty::is(Stream::Stdout) {
101                let colour = Colour::Purple.bold();
102                format!(
103                    "{}",
104                    colour.paint($($arg)*)
105                )
106            } else {
107                format!(
108                    "{}",
109                    $($arg)*
110                )
111            }
112        }
113    )
114}
115
116#[allow(unused_macros)]
117#[macro_export]
118macro_rules! black {
119    ($($arg:tt)*) => (
120        {
121            use atty::Stream;
122            use ansi_term::{Colour, Style};
123            if atty::is(Stream::Stdout) {
124                let colour = Colour::Fixed(244);
125                format!(
126                    "{}",
127                    colour.paint($($arg)*)
128                )
129            } else {
130                format!(
131                    "{}",
132                    $($arg)*
133                )
134            }
135        }
136    )
137}
138
139#[macro_export]
140macro_rules! pluralize {
141    ($value:expr, $word:expr) => {
142        if $value > 1 {
143            format!("{} {}s", $value, $word)
144        } else {
145            format!("{} {}", $value, $word)
146        }
147    };
148}
149
150#[allow(unused_macros)]
151#[macro_export]
152macro_rules! format_err {
153    ($($arg:tt)*) => (
154        {
155            format!("{} {}", red!("error:"), $($arg)*)
156        }
157    )
158}
159
160#[allow(unused_macros)]
161#[macro_export]
162macro_rules! format_warn {
163    ($($arg:tt)*) => (
164        {
165            format!("{} {}", yellow!("warn:"), $($arg)*)
166        }
167    )
168}
169
170#[allow(unused_macros)]
171#[macro_export]
172macro_rules! format_note {
173    ($($arg:tt)*) => (
174        {
175            format!("{} {}", blue!("note:"), $($arg)*)
176        }
177    )
178}