pub enum ColorMode {
On,
Off,
}Expand description
Color mode for switching coloring on/off.
Variants§
Implementations§
Source§impl ColorMode
impl ColorMode
Sourcepub fn new(s: impl AsRef<str>) -> Self
pub fn new(s: impl AsRef<str>) -> Self
Examples found in repository?
examples/switch.rs (line 7)
5fn main() {
6 let args = std::env::args().collect::<Vec<String>>();
7 let color_mode = if args.len() != 2 { ColorMode::default() } else { ColorMode::new(&args[1]) };
8 println!(
9 "{}",
10 Text::new(color_mode)
11 .s("Switching colors:\n")
12 .black()
13 .s(" 0 ")
14 .red()
15 .s(" 1 ")
16 .green()
17 .s(" 2 ")
18 .yellow()
19 .s(" 3 ")
20 .blue()
21 .s(" 4 ")
22 .magenta()
23 .s(" 5 ")
24 .cyan()
25 .s(" 6 ")
26 .white()
27 .s(" 7 ")
28 .reset()
29 );
30}More examples
examples/tree.rs (line 8)
3fn main() {
4 // Collect the command-line arguments.
5 let args = std::env::args().collect::<Vec<String>>();
6
7 // The first argument may be the color mode, like: auto, never, always
8 let color_mode = if args.len() > 1 { ColorMode::new(&args[1]) } else { ColorMode::default() };
9
10 // The second argument should be the indentation, the tree will be shifted to the right.
11 let indent = if args.len() > 2 { args[2].parse::<usize>().unwrap_or_default() } else { 0 };
12
13 // Build the tree.
14 let root = node(Color::Rgb((80, 12, 140)), color_mode)
15 .line()
16 .bold()
17 .underline()
18 .blue()
19 .s("Quantum AI Core")
20 .end()
21 .child(
22 node(Color::Yellow, color_mode)
23 .line()
24 .yellow()
25 .s("Neural Processing Unit Alpha")
26 .end()
27 .child(
28 leaf(color_mode)
29 .line()
30 .s("Synapse Array Load: 98%")
31 .end()
32 .line()
33 .s("Memory Cache Temp: -12°C")
34 .end()
35 .line()
36 .magenta()
37 .s("Quantum Bit Flux: 0.0012")
38 .end()
39 .line()
40 .bg_yellow()
41 .color(Color::Rgb((10, 10, 10)))
42 .s(" Neural Spike Rate: 14,000 Hz ")
43 .end()
44 .end(),
45 )
46 .child(leaf(color_mode).line().s("Optimization Status: ").green().bold().s("Perfect").end().end())
47 .end(),
48 )
49 .child(
50 node(Color::None, color_mode)
51 .line()
52 .bold()
53 .blue()
54 .s("Dark Matter Storage Array")
55 .end()
56 .child(leaf(color_mode).line().s("Energy Stabilizer: Online").end().end())
57 .child(
58 leaf(color_mode)
59 .line()
60 .s("Matter Density: 9.8×10^-27 kg/m³")
61 .end()
62 .line()
63 .s("Containment Field: 99.99%")
64 .end()
65 .line()
66 .bold()
67 .red()
68 .s("Particle Flux: 1.2×10^6 s^-1")
69 .end()
70 .line()
71 .s("Storage Efficiency: 87%")
72 .end()
73 .end(),
74 )
75 .child(leaf(color_mode).line().s("Backup Node: ").green().bold().underline().s("Ready").end().end())
76 .end(),
77 )
78 .child(
79 node(Color::None, color_mode)
80 .line()
81 .bold()
82 .blue()
83 .s("Interstellar Communication Hub")
84 .end()
85 .child(
86 node(Color::Yellow, color_mode)
87 .line()
88 .yellow()
89 .s("Subspace Transmitter Delta")
90 .end()
91 .child(
92 leaf(color_mode)
93 .line()
94 .s("Signal Strength: 999.9 TW")
95 .end()
96 .line()
97 .cyan()
98 .s("Latency: 0.00042 s")
99 .end()
100 .line()
101 .s("Encryption Protocol: Quantum-256")
102 .end()
103 .line()
104 .s("Active Channels: 42")
105 .end()
106 .end(),
107 )
108 .child(leaf(color_mode).line().s("Maintenance Mode: ").italic().bg_magenta().s("Idle").end().end())
109 .end(),
110 )
111 .child(
112 leaf(color_mode)
113 .line()
114 .cyan()
115 .s("Cosmic Bandwidth Allocation: 12.7 PB/s")
116 .end()
117 .line()
118 .s("Error Correction Status: Optimal")
119 .end()
120 .line()
121 .s("Packet Loss: 0.0001%")
122 .end()
123 .line()
124 .s("Routing Algorithm: Self-Adaptive AI")
125 .end()
126 .end(),
127 )
128 .child(leaf(color_mode).line().s("Hub Status: ").green().italic().bold().s("Fully Operational").end().end())
129 .end(),
130 )
131 .end();
132
133 // Print the tree with indentation.
134 print!("{:1$}", root, indent);
135}pub fn black(&self, bright: bool) -> Cow<'static, str>
pub fn red(&self, bright: bool) -> Cow<'static, str>
pub fn green(&self, bright: bool) -> Cow<'static, str>
pub fn yellow(&self, bright: bool) -> Cow<'static, str>
pub fn blue(&self, bright: bool) -> Cow<'static, str>
pub fn magenta(&self, bright: bool) -> Cow<'static, str>
pub fn cyan(&self, bright: bool) -> Cow<'static, str>
pub fn white(&self, bright: bool) -> Cow<'static, str>
pub fn bg_black(&self, bright: bool) -> Cow<'static, str>
pub fn bg_red(&self, bright: bool) -> Cow<'static, str>
pub fn bg_green(&self, bright: bool) -> Cow<'static, str>
pub fn bg_yellow(&self, bright: bool) -> Cow<'static, str>
pub fn bg_blue(&self, bright: bool) -> Cow<'static, str>
pub fn bg_magenta(&self, bright: bool) -> Cow<'static, str>
pub fn bg_cyan(&self, bright: bool) -> Cow<'static, str>
pub fn bg_white(&self, bright: bool) -> Cow<'static, str>
pub fn color(&self, c: Color, bright: bool) -> Cow<'static, str>
pub fn bg_color(&self, c: Color, bright: bool) -> Cow<'static, str>
pub fn color_8(&self, c: u8, bright: bool) -> Cow<'static, str>
pub fn bg_color_8(&self, c: u8, bright: bool) -> Cow<'static, str>
pub fn color_256(&self, c: u8) -> String
pub fn bg_color_256(&self, c: u8) -> String
pub fn color_rgb(&self, c: RgbColor) -> String
pub fn bg_color_rgb(&self, c: RgbColor) -> String
pub fn bold(&self) -> &str
pub fn italic(&self) -> &str
pub fn underline(&self) -> &str
pub fn reset(&self) -> &str
Trait Implementations§
impl Copy for ColorMode
impl Eq for ColorMode
impl StructuralPartialEq for ColorMode
Auto Trait Implementations§
impl Freeze for ColorMode
impl RefUnwindSafe for ColorMode
impl Send for ColorMode
impl Sync for ColorMode
impl Unpin for ColorMode
impl UnsafeUnpin for ColorMode
impl UnwindSafe for ColorMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more