Bläddra i källkod

added rgb color for background-color

Demonthos 3 år sedan
förälder
incheckning
82b1735f25
1 ändrade filer med 24 tillägg och 1 borttagningar
  1. 24 1
      src/attributes.rs

+ 24 - 1
src/attributes.rs

@@ -386,7 +386,30 @@ fn apply_background(name: &str, value: &str, style: &mut StyleModifer) {
                 "magenta" => style.tui_style.bg.replace(Color::Magenta),
                 "white" => style.tui_style.bg.replace(Color::White),
                 "black" => style.tui_style.bg.replace(Color::Black),
-                _ => None,
+                _ => {
+                    if value.len() == 7{
+                        let mut values = [0, 0, 0];
+                        let mut color_ok = true;
+                        for i in 0..values.len(){
+                            if let Ok(v) = u8::from_str_radix(&value[(1+2*i)..(1+2*(i+1))], 16){
+                                values[i] = v;
+                            }
+                            else{
+                                color_ok = false;
+                            }
+                        }
+                        if color_ok{
+                            let color = Color::Rgb(values[0], values[1], values[2]);
+                            style.tui_style.bg.replace(color)
+                        }
+                        else{
+                            None
+                        }
+                    }
+                    else{
+                        None
+                    }
+                },
             };
         }
         "background" => {}