nessa/algorithms/
html_ext.rs

1pub fn html_color(s: &String, color: &str) -> String {
2    format!("<span style=\"color: {};\">{}</span>", color, s)
3}
4
5pub fn html_rgb(s: &String, r: u8, g: u8, b: u8) -> String {
6    format!("<span style=\"color: rgb({}, {}, {});\">{}</span>", r, g, b, s)
7}
8pub trait HTMLColorable {
9    fn html_color(&self, color: &str) -> String;
10    fn html_rgb(&self, r: u8, g: u8, b: u8) -> String;
11    
12    fn html_cyan(&self) -> String {
13        self.html_rgb(0, 255, 255)
14    }
15    
16    fn html_green(&self) -> String {
17        self.html_rgb(78, 201, 176)
18    }
19    
20    fn html_magenta(&self) -> String {
21        self.html_rgb(197, 134, 192)
22    }
23    
24    fn html_yellow(&self) -> String {
25        self.html_rgb(220, 220, 170)
26    }
27    
28    fn html_blue(&self) -> String {
29        self.html_rgb(86, 156, 214)
30    }
31}
32
33impl HTMLColorable for &str {
34    fn html_color(&self, color: &str) -> String {
35        html_color(&self.to_string(), color)
36    }
37    
38    fn html_rgb(&self, r: u8, g: u8, b: u8) -> String {
39        html_rgb(&self.to_string(), r, g, b)
40    }
41}
42
43impl HTMLColorable for String {
44    fn html_color(&self, color: &str) -> String {
45        html_color(self, color)
46    }
47    
48    fn html_rgb(&self, r: u8, g: u8, b: u8) -> String {
49        html_rgb(self, r, g, b)
50    }
51}