Skip to main content

ColorMode

Enum ColorMode 

Source
pub enum ColorMode {
    On,
    Off,
}
Expand description

Color mode for switching coloring on/off.

Variants§

§

On

Switch coloring on.

§

Off

Switch coloring off.

Implementations§

Source§

impl ColorMode

Source

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
Hide additional 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}
Source

pub fn black(&self, bright: bool) -> Cow<'static, str>

Source

pub fn red(&self, bright: bool) -> Cow<'static, str>

Source

pub fn green(&self, bright: bool) -> Cow<'static, str>

Source

pub fn yellow(&self, bright: bool) -> Cow<'static, str>

Source

pub fn blue(&self, bright: bool) -> Cow<'static, str>

Source

pub fn magenta(&self, bright: bool) -> Cow<'static, str>

Source

pub fn cyan(&self, bright: bool) -> Cow<'static, str>

Source

pub fn white(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_black(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_red(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_green(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_yellow(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_blue(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_magenta(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_cyan(&self, bright: bool) -> Cow<'static, str>

Source

pub fn bg_white(&self, bright: bool) -> Cow<'static, str>

Source

pub fn color(&self, c: Color, bright: bool) -> Cow<'static, str>

Source

pub fn bg_color(&self, c: Color, bright: bool) -> Cow<'static, str>

Source

pub fn color_8(&self, c: u8, bright: bool) -> Cow<'static, str>

Source

pub fn bg_color_8(&self, c: u8, bright: bool) -> Cow<'static, str>

Source

pub fn color_256(&self, c: u8) -> String

Source

pub fn bg_color_256(&self, c: u8) -> String

Source

pub fn color_rgb(&self, c: RgbColor) -> String

Source

pub fn bg_color_rgb(&self, c: RgbColor) -> String

Source

pub fn bold(&self) -> &str

Source

pub fn italic(&self) -> &str

Source

pub fn underline(&self) -> &str

Source

pub fn reset(&self) -> &str

Trait Implementations§

Source§

impl Clone for ColorMode

Source§

fn clone(&self) -> ColorMode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ColorMode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ColorMode

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&String> for ColorMode

Source§

fn from(value: &String) -> Self

Creates ColorMode from string reference.

Source§

impl From<&str> for ColorMode

Source§

fn from(value: &str) -> Self

Creates ColorMode from str reference.

Source§

impl From<ColorMode> for Text

Source§

fn from(cm: ColorMode) -> Self

Converts to this type from the input type.
Source§

impl From<Option<&String>> for ColorMode

Source§

fn from(value: Option<&String>) -> Self

Creates ColorMode from optional string reference.

Source§

impl From<Option<String>> for ColorMode

Source§

fn from(value: Option<String>) -> Self

Creates ColorMode from optional string.

Source§

impl From<String> for ColorMode

Source§

fn from(value: String) -> Self

Creates ColorMode from string.

Source§

impl Hash for ColorMode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ColorMode

Source§

fn eq(&self, other: &ColorMode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ColorMode

Source§

impl Eq for ColorMode

Source§

impl StructuralPartialEq for ColorMode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.