Skip to main content

NodeLineBuilder

Struct NodeLineBuilder 

Source
pub struct NodeLineBuilder { /* private fields */ }
Expand description

Builder for TreeNode::Node’s text line.

Implementations§

Source§

impl NodeLineBuilder

Source

pub fn end(self) -> NodeBuilder

Examples found in repository?
examples/tree.rs (line 20)
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}

Trait Implementations§

Source§

impl Clone for NodeLineBuilder

Source§

fn clone(&self) -> NodeLineBuilder

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 NodeLineBuilder

Source§

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

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

impl StyledText for NodeLineBuilder

Source§

fn s<T: Display>(self, s: T) -> Self

Adds content to text.
Source§

fn reset(self) -> Self

Resets all colors and styling flags.
Source§

fn repeat<T: Display>(self, s: T, n: usize) -> Self

Adds repeated content to text.
Source§

fn plural<T: Display>(self, s: T, n: usize) -> Self

Adds s suffix to the content when the number is not 1.
Source§

fn indent<T: Display>(self, indent: usize, s: T) -> Self

Adds indented content.
Source§

fn align_left<T: Display>(self, s: T, width: usize) -> Self

Adds the content aligned left with specified width.
Source§

fn align_right<T: Display>(self, s: T, width: usize) -> Self

Adds the content aligned right with specified width.
Source§

fn align_center<T: Display>(self, s: T, width: usize) -> Self

Adds the content centered with specified width.
Source§

fn pad<T: Display>(self, ch: char, padding: usize, s: T) -> Self

Pads the content with specified character.
Source§

fn pad_left<T: Display>(self, ch: char, s: T, width: usize) -> Self

Pads the content aligned the left with specified width.
Source§

fn pad_right<T: Display>(self, ch: char, s: T, width: usize) -> Self

Pads the content aligned right with specified width.
Source§

fn pad_center<T: Display>(self, ch: char, s: T, width: usize) -> Self

Pads the content centered with specified width.
Source§

fn choose<T: Display>( self, condition: bool, when_true: T, when_false: T, ) -> Self

Adds new content based on the condition.
Source§

fn bold(self) -> Self

Style text as bold.
Source§

fn italic(self) -> Self

Style text as italic.
Source§

fn underline(self) -> Self

Style text as underlined.
Source§

fn black(self) -> Self

Sets the foreground color to black.
Source§

fn bright_black(self) -> Self

Sets the foreground color to bright black.
Source§

fn red(self) -> Self

Sets the foreground color to red.
Source§

fn bright_red(self) -> Self

Sets the foreground color to bright red.
Source§

fn green(self) -> Self

Sets the foreground color to green.
Source§

fn bright_green(self) -> Self

Sets the foreground color to bright green.
Source§

fn yellow(self) -> Self

Sets the foreground color to yellow.
Source§

fn bright_yellow(self) -> Self

Sets the foreground color to bright yellow.
Source§

fn blue(self) -> Self

Sets the foreground color to blue.
Source§

fn bright_blue(self) -> Self

Sets the foreground color to bright blue.
Source§

fn magenta(self) -> Self

Sets the foreground color to magenta.
Source§

fn bright_magenta(self) -> Self

Sets the foreground color to bright magenta.
Source§

fn cyan(self) -> Self

Sets the foreground color to cyan.
Source§

fn bright_cyan(self) -> Self

Sets the foreground color to bright cyan.
Source§

fn white(self) -> Self

Sets the foreground color to white.
Source§

fn bright_white(self) -> Self

Sets the foreground color to bright white.
Source§

fn bg_black(self) -> Self

Sets the background color to black.
Source§

fn bg_bright_black(self) -> Self

Sets the background color to bright black.
Source§

fn bg_red(self) -> Self

Sets the background color to red.
Source§

fn bg_bright_red(self) -> Self

Sets the background color to bright red.
Source§

fn bg_green(self) -> Self

Sets the background color to green.
Source§

fn bg_bright_green(self) -> Self

Sets the background color to bright green.
Source§

fn bg_yellow(self) -> Self

Sets the background color to yellow.
Source§

fn bg_bright_yellow(self) -> Self

Sets the background color to bright yellow.
Source§

fn bg_blue(self) -> Self

Sets the background color to blue.
Source§

fn bg_bright_blue(self) -> Self

Sets the background color to bright blue.
Source§

fn bg_magenta(self) -> Self

Sets the background color to magenta.
Source§

fn bg_bright_magenta(self) -> Self

Sets the background color to bright magenta.
Source§

fn bg_cyan(self) -> Self

Sets the background color to cyan.
Source§

fn bg_bright_cyan(self) -> Self

Sets the background color to bright cyan.
Source§

fn bg_white(self) -> Self

Sets the background color to white.
Source§

fn bg_bright_white(self) -> Self

Sets the background color to bright white.
Source§

fn color(self, c: Color) -> Self

Sets the color by color enumeration.
Source§

fn bright_color(self, c: Color) -> Self

Sets the bright color by color enumeration.
Source§

fn bg_color(self, c: Color) -> Self

Sets the background color by color enumeration.
Source§

fn bg_bright_color(self, c: Color) -> Self

Sets the background bright color by color enumeration.
Source§

fn color_8(self, c: u8) -> Self

Sets the color by color index.
Source§

fn bright_color_8(self, c: u8) -> Self

Sets the bright color by color index.
Source§

fn bg_color_8(self, c: u8) -> Self

Sets the background color by color index.
Source§

fn bg_bright_color_8(self, c: u8) -> Self

Sets the background bright color by color index.
Source§

fn color_256(self, c: u8) -> Self

Source§

fn bg_color_256(self, c: u8) -> Self

Source§

fn color_rgb(self, c: RgbColor) -> Self

Source§

fn bg_color_rgb(self, c: RgbColor) -> Self

Source§

fn r<T: Display>(self, s: T) -> Self

Resets all styling and then appends formatted content. Read more

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.