mi6_cli/display/
colors.rs1use termion::color;
4use termion::style;
5
6use super::terminal::{use_colors, use_colors_stderr};
7
8pub fn bold_green(text: &str) -> String {
10 if use_colors() {
11 format!(
12 "{}{}{}{}",
13 style::Bold,
14 color::Fg(color::Green),
15 text,
16 style::Reset
17 )
18 } else {
19 text.to_string()
20 }
21}
22
23pub fn bold_red(text: &str) -> String {
25 if use_colors() {
26 format!(
27 "{}{}{}{}",
28 style::Bold,
29 color::Fg(color::Red),
30 text,
31 style::Reset
32 )
33 } else {
34 text.to_string()
35 }
36}
37
38pub fn bold_yellow(text: &str) -> String {
40 if use_colors() {
41 format!(
42 "{}{}{}{}",
43 style::Bold,
44 color::Fg(color::Yellow),
45 text,
46 style::Reset
47 )
48 } else {
49 text.to_string()
50 }
51}
52
53pub fn bold_white(text: &str) -> String {
55 if use_colors() {
56 format!(
57 "{}{}{}{}",
58 style::Bold,
59 color::Fg(color::White),
60 text,
61 style::Reset
62 )
63 } else {
64 text.to_string()
65 }
66}
67
68pub fn dark_grey(text: &str) -> String {
70 if use_colors() {
71 format!(
72 "{}{}{}",
73 color::Fg(color::Rgb(128, 128, 128)),
74 text,
75 style::Reset
76 )
77 } else {
78 text.to_string()
79 }
80}
81
82pub struct StderrColors {
88 pub reset: &'static str,
89 pub bold: &'static str,
90 pub bold_white: &'static str,
91 pub bold_green: &'static str,
92 pub green: &'static str,
93 pub red: &'static str,
94 pub cyan: &'static str,
95 pub yellow: &'static str,
96}
97
98impl StderrColors {
99 pub fn new() -> Self {
104 if use_colors_stderr() {
105 Self {
106 reset: "\x1b[0m",
107 bold: "\x1b[1m",
108 bold_white: "\x1b[1;37m",
109 bold_green: "\x1b[1;32m",
110 green: "\x1b[32m",
111 red: "\x1b[31m",
112 cyan: "\x1b[36m",
113 yellow: "\x1b[33m",
114 }
115 } else {
116 Self {
117 reset: "",
118 bold: "",
119 bold_white: "",
120 bold_green: "",
121 green: "",
122 red: "",
123 cyan: "",
124 yellow: "",
125 }
126 }
127 }
128}
129
130impl Default for StderrColors {
131 fn default() -> Self {
132 Self::new()
133 }
134}