ltpp_output/output_builder/
impl.rs

1use crate::{output, ColorType, Output, OutputBuilder};
2
3impl<'a> OutputBuilder<'a> {
4    /// Creates the struct
5    ///
6    /// # Returns
7    /// - `OutputBuilder`: Output
8    pub fn new() -> Self {
9        Self {
10            output: Output::default(),
11        }
12    }
13
14    /// Creates the struct from output
15    ///
16    /// # Returns
17    /// - `OutputBuilder`: Output
18    pub fn new_from(output: Output<'a>) -> Self {
19        Self { output }
20    }
21
22    /// Sets the text.
23    ///
24    /// # Parameters
25    /// - `text`: The text to be set.
26    ///
27    /// # Returns
28    /// - `&mut Self`: A mutable reference to the struct for method chaining.
29    pub fn set_text(&mut self, text: &'a str) -> &mut Self {
30        self.output.text = text;
31        self
32    }
33
34    /// Sets the text color.
35    ///
36    /// # Parameters
37    /// - `text_color`: The color to be set for the text.
38    ///
39    /// # Returns
40    /// - `&mut Self`: A mutable reference to the struct for method chaining.
41    pub fn set_text_color(&mut self, text_color: ColorType) -> &mut Self {
42        self.output.text_color = text_color;
43        self
44    }
45
46    /// Sets the background color for the text.
47    ///
48    /// # Parameters
49    /// - `text_bg_color`: The background color to be set for the text.
50    ///
51    /// # Returns
52    /// - `&mut Self`: A mutable reference to the struct for method chaining.
53    pub fn set_text_bg_color(&mut self, text_bg_color: ColorType) -> &mut Self {
54        self.output.text_bg_color = text_bg_color;
55        self
56    }
57
58    /// Sets whether the text should be bold.
59    ///
60    /// # Parameters
61    /// - `text_blod`: A boolean indicating whether the text should be bold.
62    ///
63    /// # Returns
64    /// - `&mut Self`: A mutable reference to the struct for method chaining.
65    pub fn set_text_blod(&mut self, text_blod: bool) -> &mut Self {
66        self.output.text_blod = text_blod;
67        self
68    }
69
70    /// Sets whether to show the time.
71    ///
72    /// # Parameters
73    /// - `show_time`: A boolean indicating whether to display the time.
74    ///
75    /// # Returns
76    /// - `&mut Self`: A mutable reference to the struct for method chaining.
77    pub fn set_show_time(&mut self, show_time: bool) -> &mut Self {
78        self.output.show_time = show_time;
79        self
80    }
81
82    /// Sets the time text color.
83    ///
84    /// # Parameters
85    /// - `time_text_color`: The color to be set for the time text.
86    ///
87    /// # Returns
88    /// - `&mut Self`: A mutable reference to the struct for method chaining.
89    pub fn set_time_text_color(&mut self, time_text_color: ColorType) -> &mut Self {
90        self.output.time_text_color = time_text_color;
91        self
92    }
93
94    /// Sets the background color for the time text.
95    ///
96    /// # Parameters
97    /// - `time_bg_color`: The background color to be set for the time text.
98    ///
99    /// # Returns
100    /// - `&mut Self`: A mutable reference to the struct for method chaining.
101    pub fn set_time_bg_color(&mut self, time_bg_color: ColorType) -> &mut Self {
102        self.output.time_bg_color = time_bg_color;
103        self
104    }
105
106    /// Sets whether the time text should be bold.
107    ///
108    /// # Parameters
109    /// - `time_text_blod`: A boolean indicating whether the time text should be bold.
110    ///
111    /// # Returns
112    /// - `&mut Self`: A mutable reference to the struct for method chaining.
113    pub fn set_time_text_blod(&mut self, time_text_blod: bool) -> &mut Self {
114        self.output.time_text_blod = time_text_blod;
115        self
116    }
117
118    /// Sets the separator.
119    ///
120    /// # Parameters
121    /// - `split`: The separator string to be set.
122    ///
123    /// # Returns
124    /// - `&mut Self`: A mutable reference to the struct for method chaining.
125    pub fn set_split_text(&mut self, split: &'a str) -> &mut Self {
126        self.output.split = split;
127        self
128    }
129
130    /// Sets the separator color.
131    ///
132    /// # Parameters
133    /// - `split_color`: The color to be set for the separator.
134    ///
135    /// # Returns
136    /// - `&mut Self`: A mutable reference to the struct for method chaining.
137    pub fn set_split_text_color(&mut self, split_color: ColorType) -> &mut Self {
138        self.output.split_color = split_color;
139        self
140    }
141
142    /// Sets the background color for the separator.
143    ///
144    /// # Parameters
145    /// - `split_bg_color`: The background color to be set for the separator.
146    ///
147    /// # Returns
148    /// - `&mut Self`: A mutable reference to the struct for method chaining.
149    pub fn set_split_bg_color(&mut self, split_bg_color: ColorType) -> &mut Self {
150        self.output.split_bg_color = split_bg_color;
151        self
152    }
153
154    /// Sets whether the separator text should be bold.
155    ///
156    /// # Parameters
157    /// - `split_text_blod`: A boolean indicating whether the separator text should be bold.
158    ///
159    /// # Returns
160    /// - `&mut Self`: A mutable reference to the struct for method chaining.
161    pub fn set_split_text_blod(&mut self, split_text_blod: bool) -> &mut Self {
162        self.output.split_text_blod = split_text_blod;
163        self
164    }
165
166    /// Sets the `endl` value for the `Output`.
167    ///
168    /// # Parameters
169    /// - `endl`: A boolean value that determines whether to add a newline at the end.
170    ///
171    /// # Returns
172    /// - `&mut Self`: Returns a mutable reference to the current `Output` instance, allowing method chaining.
173    pub fn set_endl(&mut self, endl: bool) -> &mut Self {
174        self.output.endl = endl;
175        self
176    }
177
178    /// Builds and returns the Output struct.
179    ///
180    /// # Returns
181    /// - `Output`: The constructed Output struct.
182    pub fn build(&self) -> Output {
183        self.output.clone()
184    }
185
186    /// Outputs the current state of the Output struct.
187    ///
188    /// # Returns
189    /// - `()` : Nothing is returned.
190    pub fn output(&self) {
191        output(self.output.clone());
192    }
193}