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/config.rs | |
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/config.rs')
-rw-r--r-- | src/config.rs | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/src/config.rs b/src/config.rs index 8ab6e662..60887720 100644 --- a/src/config.rs +++ b/src/config.rs @@ -665,34 +665,59 @@ impl Config { /// /// The ordering returned here is expected by the terminal. Colors are simply indexed in this /// array for performance. - pub fn color_list(&self) -> [Rgb; 18] { - let colors = &self.colors; - - [ - // Normals - colors.normal.black, - colors.normal.red, - colors.normal.green, - colors.normal.yellow, - colors.normal.blue, - colors.normal.magenta, - colors.normal.cyan, - colors.normal.white, - - // Brights - colors.bright.black, - colors.bright.red, - colors.bright.green, - colors.bright.yellow, - colors.bright.blue, - colors.bright.magenta, - colors.bright.cyan, - colors.bright.white, - - // Foreground and background - colors.primary.foreground, - colors.primary.background, - ] + pub fn color_list(&self) -> Vec<Rgb> { + let mut colors = Vec::with_capacity(258); + + // Normals + colors.push(self.colors.normal.black); + colors.push(self.colors.normal.red); + colors.push(self.colors.normal.green); + colors.push(self.colors.normal.yellow); + colors.push(self.colors.normal.blue); + colors.push(self.colors.normal.magenta); + colors.push(self.colors.normal.cyan); + colors.push(self.colors.normal.white); + + // Brights + colors.push(self.colors.bright.black); + colors.push(self.colors.bright.red); + colors.push(self.colors.bright.green); + colors.push(self.colors.bright.yellow); + colors.push(self.colors.bright.blue); + colors.push(self.colors.bright.magenta); + colors.push(self.colors.bright.cyan); + colors.push(self.colors.bright.white); + + // Build colors + for r in 0..6 { + for g in 0..6 { + for b in 0..6 { + colors.push(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 }, + }); + } + } + } + + // Build grays + for i in 0..24 { + let value = i * 10 + 8; + colors.push(Rgb { + r: value, + g: value, + b: value + }); + } + + debug_assert!(colors.len() == 256); + + // Foreground and background + colors.push(self.colors.primary.foreground); + colors.push(self.colors.primary.background); + + colors } pub fn key_bindings(&self) -> &[KeyBinding] { |