diff options
Diffstat (limited to 'src/term')
| -rw-r--r-- | src/term/cell.rs | 9 | ||||
| -rw-r--r-- | src/term/color.rs | 32 | ||||
| -rw-r--r-- | src/term/mod.rs | 30 |
3 files changed, 57 insertions, 14 deletions
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), |