Skip to main content

auto

Function auto 

Source
pub fn auto() -> Text
Examples found in repository?
examples/colors.rs (line 17)
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}
More examples
Hide additional examples
examples/format.rs (line 31)
29fn main() {
30  let plain_text = "Hello ☺ world 1.999";
31  let styled_text = auto().blue().s("Hello").reset().s(" ☺ ").yellow().s("world").s(" ").magenta().s(1.999).reset();
32  display(plain_text, &styled_text, 60);
33}