diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ansi.rs | 46 | ||||
-rw-r--r-- | src/config.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 20 | ||||
-rw-r--r-- | src/term/cell.rs | 9 | ||||
-rw-r--r-- | src/term/color.rs | 32 | ||||
-rw-r--r-- | src/term/mod.rs | 30 |
6 files changed, 127 insertions, 16 deletions
diff --git a/src/ansi.rs b/src/ansi.rs index 5114f7df..2eccf335 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -442,6 +442,22 @@ pub enum NamedColor { CursorText, /// Color for the cursor itself Cursor, + /// Dim black + DimBlack, + /// Dim red + DimRed, + /// Dim green + DimGreen, + /// Dim yellow + DimYellow, + /// Dim blue + DimBlue, + /// Dim magenta + DimMagenta, + /// Dim cyan + DimCyan, + /// Dim white + DimWhite, } impl NamedColor { @@ -455,6 +471,36 @@ impl NamedColor { NamedColor::Magenta => NamedColor::BrightMagenta, NamedColor::Cyan => NamedColor::BrightCyan, NamedColor::White => NamedColor::BrightWhite, + NamedColor::DimBlack => NamedColor::Black, + NamedColor::DimRed => NamedColor::Red, + NamedColor::DimGreen => NamedColor::Green, + NamedColor::DimYellow => NamedColor::Yellow, + NamedColor::DimBlue => NamedColor::Blue, + NamedColor::DimMagenta => NamedColor::Magenta, + NamedColor::DimCyan => NamedColor::Cyan, + NamedColor::DimWhite => NamedColor::White, + val => val + } + } + + pub fn to_dim(&self) -> Self { + match *self { + NamedColor::Black => NamedColor::DimBlack, + NamedColor::Red => NamedColor::DimRed, + NamedColor::Green => NamedColor::DimGreen, + NamedColor::Yellow => NamedColor::DimYellow, + NamedColor::Blue => NamedColor::DimBlue, + NamedColor::Magenta => NamedColor::DimMagenta, + NamedColor::Cyan => NamedColor::DimCyan, + NamedColor::White => NamedColor::DimWhite, + NamedColor::BrightBlack => NamedColor::Black, + NamedColor::BrightRed => NamedColor::Red, + NamedColor::BrightGreen => NamedColor::Green, + NamedColor::BrightYellow => NamedColor::Yellow, + NamedColor::BrightBlue => NamedColor::Blue, + NamedColor::BrightMagenta => NamedColor::Magenta, + NamedColor::BrightCyan => NamedColor::Cyan, + NamedColor::BrightWhite => NamedColor::White, val => val } } diff --git a/src/config.rs b/src/config.rs index 5142b9b0..7734e7af 100644 --- a/src/config.rs +++ b/src/config.rs @@ -741,6 +741,7 @@ pub struct Colors { pub cursor: CursorColors, pub normal: AnsiColors, pub bright: AnsiColors, + pub dim: Option<AnsiColors>, } fn deserialize_cursor_colors<D>(deserializer: D) -> ::std::result::Result<CursorColors, D::Error> @@ -838,12 +839,13 @@ impl Default for Colors { magenta: Rgb {r: 0xb7, g: 0x7e, b: 0xe0}, cyan: Rgb {r: 0x54, g: 0xce, b: 0xd6}, white: Rgb {r: 0xff, g: 0xff, b: 0xff}, - } + }, + dim: None, } } } -/// The normal or bright colors section of config +/// The 8-colors sections of config #[derive(Debug, Deserialize)] pub struct AnsiColors { #[serde(deserialize_with = "rgb_from_hex")] @@ -71,6 +71,8 @@ pub mod tty; pub mod util; pub mod window; +use std::ops::Mul; + pub use grid::Grid; pub use term::Term; @@ -81,6 +83,24 @@ pub struct Rgb { pub b: u8, } +// a multiply function for Rgb, as the default dim is just *2/3 +impl Mul<f32> for Rgb { + type Output = Rgb; + + fn mul(self, rhs: f32) -> Rgb { + let result = Rgb { + r: (self.r as f32 * rhs).max(0.0).min(255.0) as u8, + g: (self.g as f32 * rhs).max(0.0).min(255.0) as u8, + b: (self.b as f32 * rhs).max(0.0).min(255.0) as u8 + }; + + trace!("Scaling RGB by {} from {:?} to {:?}", rhs, self, result); + + result + } +} + + #[cfg_attr(feature = "clippy", allow(too_many_arguments))] #[cfg_attr(feature = "clippy", allow(doc_markdown))] pub mod gl { diff --git a/src/term/cell.rs b/src/term/cell.rs index 18e03dee..d1c6877b 100644 --- a/src/term/cell.rs +++ b/src/term/cell.rs @@ -25,6 +25,8 @@ bitflags! { const WRAPLINE = 0b00010000, const WIDE_CHAR = 0b00100000, const WIDE_CHAR_SPACER = 0b01000000, + const DIM = 0b10000000, + const DIM_BOLD = 0b10000010, } } @@ -73,14 +75,21 @@ impl LineLength for grid::Row<Cell> { } impl Cell { + #[inline] pub fn bold(&self) -> bool { self.flags.contains(BOLD) } + #[inline] pub fn inverse(&self) -> bool { self.flags.contains(INVERSE) } + #[inline] + pub fn dim(&self) -> bool { + self.flags.contains(DIM) + } + pub fn new(c: char, fg: Color, bg: Color) -> Cell { Cell { c: c.into(), diff --git a/src/term/color.rs b/src/term/color.rs index 0c701c34..8f58d0ca 100644 --- a/src/term/color.rs +++ b/src/term/color.rs @@ -7,11 +7,11 @@ use config::Colors; /// List of indexed colors /// /// The first 16 entries are the standard ansi named colors. Items 16..232 are -/// the color cube. Items 233..256 are the grayscale ramp. Finally, item 256 is +/// the color cube. Items 233..256 are the grayscale ramp. Item 256 is /// the configured foreground color, item 257 is the configured background /// color, item 258 is the cursor foreground color, item 259 is the cursor -/// background color. -pub struct List([Rgb; 260]); +/// background color. Following that are 8 positions for dim colors. +pub struct List([Rgb; 268]); impl<'a> From<&'a Colors> for List { fn from(colors: &Colors) -> List { @@ -55,6 +55,32 @@ impl List { // Foreground and background for custom cursor colors self[ansi::NamedColor::CursorText] = colors.cursor.text; self[ansi::NamedColor::Cursor] = colors.cursor.cursor; + + // Dims + 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::DimMagenta] = dim.magenta; + 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::DimMagenta] = colors.normal.magenta * 0.66; + self[ansi::NamedColor::DimCyan] = colors.normal.cyan * 0.66; + self[ansi::NamedColor::DimWhite] = colors.normal.white * 0.66; + } + } } fn fill_cube(&mut self) { diff --git a/src/term/mod.rs b/src/term/mod.rs index 8563be54..d898fe2f 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -268,23 +268,30 @@ impl<'a> RenderableCellsIter<'a> { } fn compute_fg_rgb(&self, fg: &Color, cell: &Cell) -> Rgb { + use self::cell::DIM_BOLD; match *fg { Color::Spec(rgb) => rgb, Color::Named(ansi) => { - if self.config.draw_bold_text_with_bright_colors() && cell.bold() { - self.colors[ansi.to_bright()] - } else { - self.colors[ansi] + match (self.config.draw_bold_text_with_bright_colors(), cell.flags & DIM_BOLD) { + // Draw bold text in bright colors *and* contains bold flag. + (true, self::cell::DIM_BOLD) | + (true, self::cell::BOLD) => self.colors[ansi.to_bright()], + // Cell is marked as dim and not bold + (_, self::cell::DIM) => self.colors[ansi.to_dim()], + // None of the above, keep original color. + _ => self.colors[ansi] } }, Color::Indexed(idx) => { - let idx = if self.config.draw_bold_text_with_bright_colors() - && cell.bold() - && idx < 8 - { - idx + 8 - } else { + let idx = match ( + self.config.draw_bold_text_with_bright_colors(), + cell.flags & DIM_BOLD, idx + ) { + (true, self::cell::BOLD, 0...7) => idx as usize + 8, + (false, self::cell::DIM, 8...15) => idx as usize - 8, + (false, self::cell::DIM, 0...7) => idx as usize + 260, + _ => idx as usize, }; self.colors[idx] @@ -1696,7 +1703,8 @@ impl ansi::Handler for Term { Attr::Reverse => self.cursor.template.flags.insert(cell::INVERSE), Attr::CancelReverse => self.cursor.template.flags.remove(cell::INVERSE), Attr::Bold => self.cursor.template.flags.insert(cell::BOLD), - Attr::CancelBoldDim => self.cursor.template.flags.remove(cell::BOLD), + Attr::Dim => self.cursor.template.flags.insert(cell::DIM), + Attr::CancelBoldDim => self.cursor.template.flags.remove(cell::BOLD | cell::DIM), Attr::Italic => self.cursor.template.flags.insert(cell::ITALIC), Attr::CancelItalic => self.cursor.template.flags.remove(cell::ITALIC), Attr::Underscore => self.cursor.template.flags.insert(cell::UNDERLINE), |