tap/tooling/console/
styles.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub struct Color {
3 pub name: &'static str,
4 pub code: &'static str,
5}
6
7#[derive(Debug, Clone, Default, PartialEq, Eq)]
8pub struct Colors {
9 codes: Vec<Color>,
10}
11
12impl Colors {
13 pub fn new() -> Self {
14 Self { codes: Vec::new() }
15 }
16
17 pub fn add(&mut self, c: Color) -> &mut Self {
18 self.codes.push(c);
19 self
20 }
21
22 pub fn rem(&mut self, name: &str) -> &mut Self {
23 self.codes.retain(|c| c.name != name);
24 self
25 }
26
27 pub fn get(&self) -> String {
28 let mut res = String::new();
29 for col in &self.codes {
30 res.push_str(col.code);
31 }
32 res
33 }
34
35 pub fn is_empty(&self) -> bool {
36 self.codes.is_empty()
37 }
38}
39
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub struct Str {
42 pub text: String,
43 pub colors: Colors,
44}
45
46impl Str {
47 pub fn new() -> Self {
48 Self {
49 text: "".to_string(),
50 colors: Colors::new(),
51 }
52 }
53
54 pub fn add(&mut self, text: &str) -> &mut Self {
55 self.text += text;
56 self
57 }
58
59 pub fn get(&self, colored: bool) -> String {
60 let mut res = String::from("");
61 if colored {
62 res += self.colors.get().as_str();
63 }
64 res += self.text.as_str();
65 res
66 }
67}
68
69#[derive(Debug, Clone, PartialEq, Eq)]
70pub struct Text {
71 pub text: Vec<Str>,
72}
73
74impl Text {
75 pub fn new() -> Self {
76 Self { text: vec![] }
77 }
78
79 pub fn get(&self, colored: bool) -> String {
80 let mut res = String::from("");
81 for text in self.text.iter() {
82 res.push_str(&text.get(colored));
83 }
84 res
85 }
86}