diff options
Diffstat (limited to 'src/term/color.rs')
-rw-r--r-- | src/term/color.rs | 99 |
1 files changed, 44 insertions, 55 deletions
diff --git a/src/term/color.rs b/src/term/color.rs index abd7527a..39def612 100644 --- a/src/term/color.rs +++ b/src/term/color.rs @@ -1,5 +1,5 @@ -use std::ops::{Index, IndexMut, Mul}; use std::fmt; +use std::ops::{Index, IndexMut, Mul}; use crate::ansi; use crate::config::Colors; @@ -24,7 +24,7 @@ impl Mul<f32> for Rgb { let result = Rgb { r: (f32::from(self.r) * rhs).max(0.0).min(255.0) as u8, g: (f32::from(self.g) * rhs).max(0.0).min(255.0) as u8, - b: (f32::from(self.b) * rhs).max(0.0).min(255.0) as u8 + b: (f32::from(self.b) * rhs).max(0.0).min(255.0) as u8, }; trace!("Scaling RGB by {} from {:?} to {:?}", rhs, self, result); @@ -60,28 +60,26 @@ impl<'a> From<&'a Colors> for List { impl List { pub fn fill_named(&mut self, colors: &Colors) { // Normals - self[ansi::NamedColor::Black] = colors.normal.black; - self[ansi::NamedColor::Red] = colors.normal.red; - self[ansi::NamedColor::Green] = colors.normal.green; - self[ansi::NamedColor::Yellow] = colors.normal.yellow; - self[ansi::NamedColor::Blue] = colors.normal.blue; + self[ansi::NamedColor::Black] = colors.normal.black; + self[ansi::NamedColor::Red] = colors.normal.red; + self[ansi::NamedColor::Green] = colors.normal.green; + self[ansi::NamedColor::Yellow] = colors.normal.yellow; + self[ansi::NamedColor::Blue] = colors.normal.blue; self[ansi::NamedColor::Magenta] = colors.normal.magenta; - self[ansi::NamedColor::Cyan] = colors.normal.cyan; - self[ansi::NamedColor::White] = colors.normal.white; + self[ansi::NamedColor::Cyan] = colors.normal.cyan; + self[ansi::NamedColor::White] = colors.normal.white; // Brights - self[ansi::NamedColor::BrightBlack] = colors.bright.black; - self[ansi::NamedColor::BrightRed] = colors.bright.red; - self[ansi::NamedColor::BrightGreen] = colors.bright.green; - self[ansi::NamedColor::BrightYellow] = colors.bright.yellow; - self[ansi::NamedColor::BrightBlue] = colors.bright.blue; + self[ansi::NamedColor::BrightBlack] = colors.bright.black; + self[ansi::NamedColor::BrightRed] = colors.bright.red; + self[ansi::NamedColor::BrightGreen] = colors.bright.green; + self[ansi::NamedColor::BrightYellow] = colors.bright.yellow; + self[ansi::NamedColor::BrightBlue] = colors.bright.blue; self[ansi::NamedColor::BrightMagenta] = colors.bright.magenta; - self[ansi::NamedColor::BrightCyan] = colors.bright.cyan; - self[ansi::NamedColor::BrightWhite] = colors.bright.white; - self[ansi::NamedColor::BrightForeground] = colors - .primary - .bright_foreground - .unwrap_or(colors.primary.foreground); + self[ansi::NamedColor::BrightCyan] = colors.bright.cyan; + self[ansi::NamedColor::BrightWhite] = colors.bright.white; + self[ansi::NamedColor::BrightForeground] = + colors.primary.bright_foreground.unwrap_or(colors.primary.foreground); // Foreground and background self[ansi::NamedColor::Foreground] = colors.primary.foreground; @@ -89,36 +87,34 @@ impl List { // Foreground and background for custom cursor colors self[ansi::NamedColor::CursorText] = colors.cursor.text.unwrap_or_else(Rgb::default); - self[ansi::NamedColor::Cursor] = colors.cursor.cursor.unwrap_or_else(Rgb::default); + self[ansi::NamedColor::Cursor] = colors.cursor.cursor.unwrap_or_else(Rgb::default); // Dims - self[ansi::NamedColor::DimForeground] = colors - .primary - .dim_foreground - .unwrap_or(colors.primary.foreground * 0.66); + self[ansi::NamedColor::DimForeground] = + colors.primary.dim_foreground.unwrap_or(colors.primary.foreground * 0.66); match colors.dim { Some(ref dim) => { trace!("Using config-provided dim colors"); - self[ansi::NamedColor::DimBlack] = dim.black; - self[ansi::NamedColor::DimRed] = dim.red; - self[ansi::NamedColor::DimGreen] = dim.green; - self[ansi::NamedColor::DimYellow] = dim.yellow; - self[ansi::NamedColor::DimBlue] = dim.blue; + self[ansi::NamedColor::DimBlack] = dim.black; + self[ansi::NamedColor::DimRed] = dim.red; + self[ansi::NamedColor::DimGreen] = dim.green; + self[ansi::NamedColor::DimYellow] = dim.yellow; + self[ansi::NamedColor::DimBlue] = dim.blue; self[ansi::NamedColor::DimMagenta] = dim.magenta; - self[ansi::NamedColor::DimCyan] = dim.cyan; - self[ansi::NamedColor::DimWhite] = dim.white; - } + self[ansi::NamedColor::DimCyan] = dim.cyan; + self[ansi::NamedColor::DimWhite] = dim.white; + }, None => { trace!("Deriving dim colors from normal colors"); - self[ansi::NamedColor::DimBlack] = colors.normal.black * 0.66; - self[ansi::NamedColor::DimRed] = colors.normal.red * 0.66; - self[ansi::NamedColor::DimGreen] = colors.normal.green * 0.66; - self[ansi::NamedColor::DimYellow] = colors.normal.yellow * 0.66; - self[ansi::NamedColor::DimBlue] = colors.normal.blue * 0.66; + self[ansi::NamedColor::DimBlack] = colors.normal.black * 0.66; + self[ansi::NamedColor::DimRed] = colors.normal.red * 0.66; + self[ansi::NamedColor::DimGreen] = colors.normal.green * 0.66; + self[ansi::NamedColor::DimYellow] = colors.normal.yellow * 0.66; + self[ansi::NamedColor::DimBlue] = colors.normal.blue * 0.66; self[ansi::NamedColor::DimMagenta] = colors.normal.magenta * 0.66; - self[ansi::NamedColor::DimCyan] = colors.normal.cyan * 0.66; - self[ansi::NamedColor::DimWhite] = colors.normal.white * 0.66; - } + self[ansi::NamedColor::DimCyan] = colors.normal.cyan * 0.66; + self[ansi::NamedColor::DimWhite] = colors.normal.white * 0.66; + }, } } @@ -129,14 +125,13 @@ impl List { for g in 0..6 { for b in 0..6 { // Override colors 16..232 with the config (if present) - if let Some(indexed_color) = colors - .indexed_colors - .iter() - .find(|ic| ic.index == index as u8) + if let Some(indexed_color) = + colors.indexed_colors.iter().find(|ic| ic.index == index as u8) { self[index] = indexed_color.color; } else { - self[index] = Rgb { r: if r == 0 { 0 } else { r * 40 + 55 }, + self[index] = Rgb { + r: if r == 0 { 0 } else { r * 40 + 55 }, b: if b == 0 { 0 } else { b * 40 + 55 }, g: if g == 0 { 0 } else { g * 40 + 55 }, }; @@ -157,10 +152,8 @@ impl List { let color_index = 16 + 216 + i; // Override colors 232..256 with the config (if present) - if let Some(indexed_color) = colors - .indexed_colors - .iter() - .find(|ic| ic.index == color_index) + if let Some(indexed_color) = + colors.indexed_colors.iter().find(|ic| ic.index == color_index) { self[index] = indexed_color.color; index += 1; @@ -168,11 +161,7 @@ impl List { } let value = i * 10 + 8; - self[index] = Rgb { - r: value, - g: value, - b: value - }; + self[index] = Rgb { r: value, g: value, b: value }; index += 1; } |