Skip to main content

colors/
colors.rs

1use antex::{Color, StyledText, Text, auto};
2
3const LABELS: [&str; 8] = [" whole ", " error ", " compiling ", " warning ", " plan ", " finished ", " before ", " completion "];
4
5const COLORS: [Color; 8] = [
6  Color::Black,
7  Color::Red,
8  Color::Green,
9  Color::Yellow,
10  Color::Blue,
11  Color::Magenta,
12  Color::Cyan,
13  Color::White,
14];
15
16fn bold() -> Text {
17  auto().bold()
18}
19
20fn reset() -> Text {
21  auto().reset()
22}
23
24fn print_colors(normal: Text, bright: Text) {
25  println!("         normal: {}", normal.clone() + reset());
26  println!("         bright: {}", bright.clone() + reset());
27  println!("           bold: {}", bold() + normal + reset());
28  println!("  bold & bright: {}", bold() + bright + reset());
29}
30
31fn print_bg_colors(normal: Text, bright: Text) {
32  println!("         normal: {}", normal + reset());
33  println!("         bright: {}", bright + reset());
34}
35
36fn basic_colors() {
37  let normal_colors = auto()
38    .black()
39    .s(LABELS[0])
40    .red()
41    .s(LABELS[1])
42    .green()
43    .s(LABELS[2])
44    .yellow()
45    .s(LABELS[3])
46    .blue()
47    .s(LABELS[4])
48    .magenta()
49    .s(LABELS[5])
50    .cyan()
51    .s(LABELS[6])
52    .white()
53    .s(LABELS[7]);
54  let bright_colors = auto()
55    .bright_black()
56    .s(LABELS[0])
57    .bright_red()
58    .s(LABELS[1])
59    .bright_green()
60    .s(LABELS[2])
61    .bright_yellow()
62    .s(LABELS[3])
63    .bright_blue()
64    .s(LABELS[4])
65    .bright_magenta()
66    .s(LABELS[5])
67    .bright_cyan()
68    .s(LABELS[6])
69    .bright_white()
70    .s(LABELS[7]);
71  print_colors(normal_colors, bright_colors);
72}
73
74fn enumerated_colors() {
75  let mut normal_colors = auto();
76  for (index, color) in COLORS.iter().enumerate() {
77    normal_colors += auto().color(*color).s(LABELS[index]);
78  }
79  let mut bright_colors = auto();
80  for (index, color) in COLORS.iter().enumerate() {
81    bright_colors += auto().bright_color(*color).s(LABELS[index]);
82  }
83  print_colors(normal_colors, bright_colors);
84}
85
86fn indexed_colors() {
87  let mut normal_colors = auto();
88  for (index, label) in LABELS.iter().enumerate() {
89    normal_colors += auto().color_8(index as u8).s(label);
90  }
91  let mut bright_colors = auto();
92  for (index, label) in LABELS.iter().enumerate() {
93    bright_colors += auto().bright_color_8(index as u8).s(label);
94  }
95  print_colors(normal_colors, bright_colors);
96}
97
98fn basic_bg_colors() {
99  let normal_colors = auto()
100    .white()
101    .bg_black()
102    .s(LABELS[0])
103    .bg_red()
104    .s(LABELS[1])
105    .bg_green()
106    .s(LABELS[2])
107    .bg_yellow()
108    .s(LABELS[3])
109    .bg_blue()
110    .s(LABELS[4])
111    .bg_magenta()
112    .s(LABELS[5])
113    .bg_cyan()
114    .s(LABELS[6])
115    .bg_white()
116    .s(LABELS[7]);
117  let bright_colors = auto()
118    .bg_bright_black()
119    .s(LABELS[0])
120    .bg_bright_red()
121    .s(LABELS[1])
122    .bg_bright_green()
123    .s(LABELS[2])
124    .bg_bright_yellow()
125    .s(LABELS[3])
126    .bg_bright_blue()
127    .s(LABELS[4])
128    .bg_bright_magenta()
129    .s(LABELS[5])
130    .bg_bright_cyan()
131    .s(LABELS[6])
132    .bg_bright_white()
133    .s(LABELS[7]);
134  print_bg_colors(normal_colors, bright_colors);
135}
136
137fn main() {
138  println!("\nColors set using color functions");
139  println!("---------------------------------------------------------------------------------------");
140  basic_colors();
141  println!("\nColors set using color enumeration");
142  println!("---------------------------------------------------------------------------------------");
143  enumerated_colors();
144  println!("\nColors set using color indexes");
145  println!("---------------------------------------------------------------------------------------");
146  indexed_colors();
147  println!("\nBackground colors set using color functions");
148  println!("---------------------------------------------------------------------------------------");
149  basic_bg_colors();
150  println!();
151}