-
Notifications
You must be signed in to change notification settings - Fork 56
/
colors.rs
90 lines (82 loc) · 2.56 KB
/
colors.rs
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
fn main() {
#[cfg(not(feature = "colors"))]
println!("Feature color is switched off");
#[cfg(feature = "colors")]
{
use nu_ansi_term::Color;
use std::io::IsTerminal;
for i in 0..=255 {
println!("{}: {}", i, Color::Fixed(i).paint(i.to_string()));
}
println!();
if std::io::stdout().is_terminal() {
println!(
"Stdout is considered a tty - \
flexi_logger::AdaptiveFormat will use colors",
);
} else {
println!(
"Stdout is not considered a tty - \
flexi_logger::AdaptiveFormat will NOT use colors"
);
}
if std::io::stderr().is_terminal() {
println!(
"Stderr is considered a tty - \
flexi_logger::AdaptiveFormat will use colors",
);
} else {
println!(
"Stderr is not considered a tty - \
flexi_logger::AdaptiveFormat will NOT use colors!"
);
}
#[cfg(target_os = "windows")]
if nu_ansi_term::enable_ansi_support().is_err() {
println!("Unsupported windows console detected, coloring will likely not work");
}
println!(
"\n{}",
Color::Fixed(196)
.bold()
.paint("err! output (red) with default palette")
);
println!(
"{}",
Color::Fixed(208)
.bold()
.paint("warn! output (yellow) with default palette")
);
println!("info! output (normal) with default palette");
println!(
"{}",
Color::Fixed(7).paint("debug! output (normal) with default palette")
);
println!(
"{}",
Color::Fixed(8).paint("trace! output (grey) with default palette")
);
println!(
"\n{}",
Color::Red
.bold()
.paint("err! output (red) with env_logger-palette")
);
println!(
"{}",
Color::Yellow.paint("warn! output (yellow) with env_logger-palette")
);
println!(
"{}",
Color::Green.paint("info! output (green) with env_logger-palette")
);
println!(
"{}",
Color::Blue.paint("debug! output (blue) with env_logger-palette")
);
println!(
"{}",
Color::Cyan.paint("trace! output (cyan) with env_logger-palette")
);
}
}