1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Macros for creating coloured console output.
//!
//! The macros are based on the following colours:
//!
//! * grey
//! * red
//! * green
//! * yellow
//! * blue
//! * magenta
//! * cyan
//! * black
//! * white
//!
//! There are dark versions of each colour except black and white, and for all colours there is a
//! version with suffix `_ln` which appends a newline (similar to [`print!`] and [`println!`]).
//!
//! There are also `prnt!` and `prnt_ln!` available which print using the current default foreground
//! colour.
//!
//! Every variant also has a version with prefix `e_`.  Variants with this prefix output to stderr,
//! while those without the `e_` prefix output to stdout.

/// Helpers and consts which should not be used directly outside of this crate.
#[doc(hidden)]
pub mod internal;

#[rustfmt::skip]
macro_rules! make_macro {
    ($dollar:tt $name:ident, $newline:literal, $colour:ident, $output:ident) => {
        #[macro_export]
        macro_rules! $name {
            () => {
                $crate::internal::write::<_, $newline>(
                    std::io::$output().lock(),
                    stringify!($output),
                    $crate::internal::Colour::$colour,
                    None
                )
            };
            ($dollar($dollar args:expr),*) => {
                $crate::internal::write::<_, $newline>(
                    std::io::$output().lock(),
                    stringify!($output),
                    $crate::internal::Colour::$colour,
                    Some(format_args!($dollar($dollar args),*))
                )
            };
        }
    };
}

make_macro!($ black, false, Black, stdout);
make_macro!($ e_black, false, Black, stderr);
make_macro!($ black_ln, true, Black, stdout);
make_macro!($ e_black_ln, true, Black, stderr);

make_macro!($ dark_red, false, DarkRed, stdout);
make_macro!($ e_dark_red, false, DarkRed, stderr);
make_macro!($ dark_red_ln, true, DarkRed, stdout);
make_macro!($ e_dark_red_ln, true, DarkRed, stderr);

make_macro!($ dark_green, false, DarkGreen, stdout);
make_macro!($ e_dark_green, false, DarkGreen, stderr);
make_macro!($ dark_green_ln, true, DarkGreen, stdout);
make_macro!($ e_dark_green_ln, true, DarkGreen, stderr);

make_macro!($ dark_yellow, false, DarkYellow, stdout);
make_macro!($ e_dark_yellow, false, DarkYellow, stderr);
make_macro!($ dark_yellow_ln, true, DarkYellow, stdout);
make_macro!($ e_dark_yellow_ln, true, DarkYellow, stderr);

make_macro!($ dark_blue, false, DarkBlue, stdout);
make_macro!($ e_dark_blue, false, DarkBlue, stderr);
make_macro!($ dark_blue_ln, true, DarkBlue, stdout);
make_macro!($ e_dark_blue_ln, true, DarkBlue, stderr);

make_macro!($ dark_magenta, false, DarkMagenta, stdout);
make_macro!($ e_dark_magenta, false, DarkMagenta, stderr);
make_macro!($ dark_magenta_ln, true, DarkMagenta, stdout);
make_macro!($ e_dark_magenta_ln, true, DarkMagenta, stderr);

make_macro!($ dark_cyan, false, DarkCyan, stdout);
make_macro!($ e_dark_cyan, false, DarkCyan, stderr);
make_macro!($ dark_cyan_ln, true, DarkCyan, stdout);
make_macro!($ e_dark_cyan_ln, true, DarkCyan, stderr);

make_macro!($ grey, false, Grey, stdout);
make_macro!($ e_grey, false, Grey, stderr);
make_macro!($ grey_ln, true, Grey, stdout);
make_macro!($ e_grey_ln, true, Grey, stderr);

make_macro!($ dark_grey, false, DarkGrey, stdout);
make_macro!($ e_dark_grey, false, DarkGrey, stderr);
make_macro!($ dark_grey_ln, true, DarkGrey, stdout);
make_macro!($ e_dark_grey_ln, true, DarkGrey, stderr);

make_macro!($ red, false, Red, stdout);
make_macro!($ e_red, false, Red, stderr);
make_macro!($ red_ln, true, Red, stdout);
make_macro!($ e_red_ln, true, Red, stderr);

make_macro!($ green, false, Green, stdout);
make_macro!($ e_green, false, Green, stderr);
make_macro!($ green_ln, true, Green, stdout);
make_macro!($ e_green_ln, true, Green, stderr);

make_macro!($ yellow, false, Yellow, stdout);
make_macro!($ e_yellow, false, Yellow, stderr);
make_macro!($ yellow_ln, true, Yellow, stdout);
make_macro!($ e_yellow_ln, true, Yellow, stderr);

make_macro!($ blue, false, Blue, stdout);
make_macro!($ e_blue, false, Blue, stderr);
make_macro!($ blue_ln, true, Blue, stdout);
make_macro!($ e_blue_ln, true, Blue, stderr);

make_macro!($ magenta, false, Magenta, stdout);
make_macro!($ e_magenta, false, Magenta, stderr);
make_macro!($ magenta_ln, true, Magenta, stdout);
make_macro!($ e_magenta_ln, true, Magenta, stderr);

make_macro!($ cyan, false, Cyan, stdout);
make_macro!($ e_cyan, false, Cyan, stderr);
make_macro!($ cyan_ln, true, Cyan, stdout);
make_macro!($ e_cyan_ln, true, Cyan, stderr);

make_macro!($ white, false, White, stdout);
make_macro!($ e_white, false, White, stderr);
make_macro!($ white_ln, true, White, stdout);
make_macro!($ e_white_ln, true, White, stderr);

make_macro!($ prnt, false, Reset, stdout);
make_macro!($ e_prnt, false, Reset, stderr);
make_macro!($ prnt_ln, true, Reset, stdout);
make_macro!($ e_prnt_ln, true, Reset, stderr);