aboutsummaryrefslogtreecommitdiff
path: root/src/term
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-09-23 23:05:15 +0000
committerGitHub <noreply@github.com>2018-09-23 23:05:15 +0000
commitcd79680ba23b3d9c22372c95fa53dec5b4ea7c8e (patch)
tree0d720395a394c4ddff9088e5597b56b776d26758 /src/term
parent9b694fcc547f664ed0fecdd5c84c067d7d3e7f14 (diff)
downloadalacritty-cd79680ba23b3d9c22372c95fa53dec5b4ea7c8e.tar.gz
alacritty-cd79680ba23b3d9c22372c95fa53dec5b4ea7c8e.zip
Implement config option for term colors 16..256
This adds a config option which allows setting terminal colors above the 0..16 range. Live config reload already works for this, so it is possible to change these colors the same way it works with the normal colors. If a color below 16 is specified, the configuration will throw an error, so the normal colors can't be overridden. This is just to prevent possible complications with the settings that already exist.
Diffstat (limited to 'src/term')
-rw-r--r--src/term/color.rs36
-rw-r--r--src/term/mod.rs2
2 files changed, 34 insertions, 4 deletions
diff --git a/src/term/color.rs b/src/term/color.rs
index 6acd092a..276a6897 100644
--- a/src/term/color.rs
+++ b/src/term/color.rs
@@ -23,8 +23,8 @@ impl<'a> From<&'a Colors> for List {
let mut list: List = unsafe { ::std::mem::uninitialized() };
list.fill_named(colors);
- list.fill_cube();
- list.fill_gray_ramp();
+ list.fill_cube(colors);
+ list.fill_gray_ramp(colors);
list
}
@@ -95,12 +95,26 @@ impl List {
}
}
- fn fill_cube(&mut self) {
+ pub fn fill_cube(&mut self, colors: &Colors) {
let mut index: usize = 16;
// Build colors
for r in 0..6 {
for g in 0..6 {
for b in 0..6 {
+ // Index of the color is number of named colors + rgb
+ let color_index = 16 + r + g + b;
+
+ // Override colors 16..232 with the config (if present)
+ if let Some(indexed_color) = colors
+ .indexed_colors
+ .iter()
+ .find(|ic| ic.index == color_index)
+ {
+ self[index] = indexed_color.color;
+ index += 1;
+ continue;
+ }
+
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 },
@@ -113,10 +127,24 @@ impl List {
debug_assert!(index == 232);
}
- fn fill_gray_ramp(&mut self) {
+ pub fn fill_gray_ramp(&mut self, colors: &Colors) {
let mut index: usize = 232;
for i in 0..24 {
+ // Index of the color is number of named colors + number of cube colors + i
+ 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)
+ {
+ self[index] = indexed_color.color;
+ index += 1;
+ continue;
+ }
+
let value = i * 10 + 8;
self[index] = Rgb {
r: value,
diff --git a/src/term/mod.rs b/src/term/mod.rs
index c2759802..f6f53dbe 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -900,6 +900,8 @@ impl Term {
pub fn update_config(&mut self, config: &Config) {
self.semantic_escape_chars = config.selection().semantic_escape_chars.clone();
self.original_colors.fill_named(config.colors());
+ self.original_colors.fill_cube(config.colors());
+ self.original_colors.fill_gray_ramp(config.colors());
for i in 0..color::COUNT {
if !self.color_modified[i] {
self.colors[i] = self.original_colors[i];