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
use std::fmt;
use termion::color as tmc;
macro_rules! define_color {
(
$($var:ident => $method:ident),+$(,)*
) => {
// Color wraps termion::Color as enum.
// Without this we need to use Trait object to hold various colors as a same field
// but it makes difficult to clone/copy values.
#[derive(Debug, Clone, Copy)]
pub enum Color {
$($var(tmc::$var),)*
}
impl Color {
$(
pub fn $method() -> Color {
Color::$var(tmc::$var)
}
)*
}
impl tmc::Color for Color {
fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
$(
Color::$var(c) => c.write_fg(f),
)*
}
}
fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
$(
Color::$var(c) => c.write_bg(f),
)*
}
}
}
};
}
define_color! {
Red => red,
Blue => blue,
Yellow => yellow,
Green => green,
Cyan => cyan,
Magenta => magenta,
Black => black,
White => white,
LightBlue => light_blue,
LightRed => light_red,
LightMagenta => light_magenta,
}