diff options
author | Joe Wilm <joe@jwilm.com> | 2016-12-04 11:14:27 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-12-11 20:23:41 -0800 |
commit | 23e36f19255db60084c2c240a166d137f6c12c3e (patch) | |
tree | 8f37cb27e0c9ed218e26bddc691b3ae15824e50e /src/term | |
parent | 3151ef862596bbfc69b2941765f2574348d85a8f (diff) | |
download | alacritty-23e36f19255db60084c2c240a166d137f6c12c3e.tar.gz alacritty-23e36f19255db60084c2c240a166d137f6c12c3e.zip |
Add support for indexed colors
ANSI escape sequences like `\x1b[48;5;10m` were not supported until now.
Specifically, the second attribute, 5, says that the following attribute
is a color index.
The ref tests were updated since `enum Color` variants changed.
Diffstat (limited to 'src/term')
-rw-r--r-- | src/term/cell.rs | 11 | ||||
-rw-r--r-- | src/term/mod.rs | 32 |
2 files changed, 13 insertions, 30 deletions
diff --git a/src/term/cell.rs b/src/term/cell.rs index 506fde0e..df648294 100644 --- a/src/term/cell.rs +++ b/src/term/cell.rs @@ -15,8 +15,7 @@ use std::mem; -use ansi; -use Rgb; +use ansi::{NamedColor, Color}; bitflags! { #[derive(Serialize, Deserialize)] @@ -28,12 +27,6 @@ bitflags! { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub enum Color { - Rgb(Rgb), - Ansi(ansi::Color), -} - #[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] pub struct Cell { pub c: char, @@ -59,7 +52,7 @@ impl Cell { #[inline] pub fn is_empty(&self) -> bool { self.c == ' ' && - self.bg == Color::Ansi(ansi::Color::Background) && + self.bg == Color::Named(NamedColor::Background) && !self.flags.contains(INVERSE) } diff --git a/src/term/mod.rs b/src/term/mod.rs index acbb70ac..9ed19c81 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -20,7 +20,7 @@ use std::cmp; use ansi::{self, Attr, Handler}; use grid::{Grid, ClearRegion}; use index::{Cursor, Column, Line}; -use ansi::Color; +use ansi::{Color, NamedColor}; pub mod cell; pub use self::cell::Cell; @@ -250,8 +250,8 @@ impl Term { pub fn new(size: SizeInfo) -> Term { let template = Cell::new( ' ', - cell::Color::Ansi(Color::Foreground), - cell::Color::Ansi(Color::Background) + Color::Named(NamedColor::Foreground), + Color::Named(NamedColor::Background) ); let num_cols = size.cols(); @@ -800,21 +800,11 @@ impl ansi::Handler for Term { fn terminal_attribute(&mut self, attr: Attr) { debug_println!("Set Attribute: {:?}", attr); match attr { - Attr::Foreground(named_color) => { - self.template_cell.fg = cell::Color::Ansi(named_color); - }, - Attr::Background(named_color) => { - self.template_cell.bg = cell::Color::Ansi(named_color); - }, - Attr::ForegroundSpec(rgb) => { - self.template_cell.fg = cell::Color::Rgb(rgb); - }, - Attr::BackgroundSpec(rgb) => { - self.template_cell.bg = cell::Color::Rgb(rgb); - }, + Attr::Foreground(color) => self.template_cell.fg = color, + Attr::Background(color) => self.template_cell.bg = color, Attr::Reset => { - self.template_cell.fg = cell::Color::Ansi(Color::Foreground); - self.template_cell.bg = cell::Color::Ansi(Color::Background); + self.template_cell.fg = Color::Named(NamedColor::Foreground); + self.template_cell.bg = Color::Named(NamedColor::Background); self.template_cell.flags = cell::Flags::empty(); }, Attr::Reverse => self.template_cell.flags.insert(cell::INVERSE), @@ -888,10 +878,10 @@ mod tests { use super::limit; - use ansi::{Color}; + use ansi::{Color, NamedColor}; use grid::Grid; use index::{Line, Column}; - use term::{cell, Cell}; + use term::{Cell}; /// Check that the grid can be serialized back and forth losslessly /// @@ -901,8 +891,8 @@ mod tests { fn grid_serde() { let template = Cell::new( ' ', - cell::Color::Ansi(Color::Foreground), - cell::Color::Ansi(Color::Background) + Color::Named(NamedColor::Foreground), + Color::Named(NamedColor::Background) ); let grid = Grid::new(Line(24), Column(80), &template); |