ltpp_output/output/
output.rs

1use task::r#type::Task;
2
3use crate::text::r#type::Text;
4use crate::time::time::get_now_time_format;
5use crate::*;
6use std::borrow::Cow;
7
8/// Output
9///
10/// [Official Documentation](https://docs.ltpp.vip/LTPP-RUST-OUTPUT/),
11///
12/// # Parameters
13/// - `Output`: The output struct
14///
15/// # Code Example
16///
17/// ## Using the Struct
18///
19/// ### Using the output Function
20///
21/// ```rust
22/// use ltpp_output::*;
23/// ```
24///
25/// ## Using the Constructor
26///
27/// ### Using the output Function
28///
29/// ```rust
30/// use ltpp_output::*;
31/// ```
32pub fn output(output: Output) {
33    // Text
34    let text: &str = output.text;
35    let text_color: ColorType = output.text_color.clone();
36    let text_bg_color: ColorType = output.text_bg_color.clone();
37    let text_blod: bool = output.text_blod.clone();
38    // Time
39    let show_time: bool = output.show_time.clone();
40    let time_color: ColorType = output.time_text_color.clone();
41    let time_bg_color: ColorType = output.time_bg_color.clone();
42    let time_text_blod: bool = output.time_text_blod.clone();
43    // Separator
44    let split: &str = output.split.clone();
45    let split_color: ColorType = output.split_color.clone();
46    let split_bg_color: ColorType = output.split_bg_color.clone();
47    let split_text_blod: bool = output.time_text_blod.clone();
48    // endl
49    let endl: bool = output.endl;
50    let mut output: String = String::new();
51
52    let mut task_list: Task<'_> = Task::new();
53
54    // Add time
55    let time_str: &String = if show_time {
56        &format!("[{}]", get_now_time_format())
57    } else {
58        &String::new()
59    };
60    task_list.add(Text {
61        text: time_str,
62        text_color: time_color,
63        text_bg_color: time_bg_color,
64        blod: time_text_blod,
65        endl: false,
66    });
67
68    // Add separator
69    task_list.add(Text {
70        text: split,
71        text_color: split_color,
72        text_bg_color: split_bg_color,
73        blod: split_text_blod,
74        endl: false,
75    });
76
77    // Add text
78    task_list.add(Text {
79        text,
80        text_color,
81        text_bg_color,
82        blod: text_blod,
83        endl,
84    });
85
86    // run
87    task_list.run_all();
88}