/ src / output_builder.rs
output_builder.rs
 1  pub struct FennecOutput{
 2      output: String
 3  }
 4  
 5  pub enum Formating{
 6      Normal,
 7      Bold,
 8      Dim,
 9      Italic,
10      Underlined,
11      Blinking,
12      Reverse,
13      Invisible,
14  }
15  
16  impl FennecOutput {
17  
18      pub fn new() -> FennecOutput{
19         let output = "".to_string();
20          FennecOutput{
21             output
22         }
23      }
24      pub fn append(&mut self,input : String, formating: Vec<Formating>) -> FennecOutput{
25          
26          for format in &formating {
27              match format {
28                  Formating::Normal => {
29                      let output = format!("{}\\033[0m",self.output);
30                      self.output = output
31                  }
32                  Formating::Bold => {
33                      let output = format!("{}\\033[1m",self.output);
34                      self.output = output
35                  }
36                  Formating::Dim => {
37                      let output = format!("{}\\033[2m",self.output);
38                      self.output = output
39                  }
40                  Formating::Italic => {
41                      let output = format!("{}\\033[3m",self.output);
42                      self.output = output
43                  }
44                  Formating::Underlined => {
45                      let output = format!("{}\\033[4m",self.output);
46                      self.output = output
47                  }
48                  Formating::Blinking => {}
49                  Formating::Reverse => {}
50                  Formating::Invisible => {}
51              }
52          }
53  
54          self.output = format!("{}{input}",self.output);
55          
56          for _format in formating {
57              self.output = format!("{}\\033[0m",self.output)
58          }
59          
60          self
61      }
62      
63      pub fn to_string(&self) -> String {
64          let result = self.output.clone();
65          result
66      }
67  
68  }