diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-09-23 23:05:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-23 23:05:15 +0000 |
commit | cd79680ba23b3d9c22372c95fa53dec5b4ea7c8e (patch) | |
tree | 0d720395a394c4ddff9088e5597b56b776d26758 /src/config.rs | |
parent | 9b694fcc547f664ed0fecdd5c84c067d7d3e7f14 (diff) | |
download | alacritty-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/config.rs')
-rw-r--r-- | src/config.rs | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index bd06641a..42d65c91 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1100,16 +1100,42 @@ pub struct Colors { pub bright: AnsiColors, #[serde(default, deserialize_with = "failure_default")] pub dim: Option<AnsiColors>, + #[serde(default, deserialize_with = "failure_default_vec")] + pub indexed_colors: Vec<IndexedColor>, } -fn deserialize_cursor_colors<'a, D>(deserializer: D) -> ::std::result::Result<CursorColors, D::Error> +#[derive(Debug, Deserialize)] +pub struct IndexedColor { + #[serde(deserialize_with = "deserialize_color_index")] + pub index: u8, + #[serde(deserialize_with = "rgb_from_hex")] + pub color: Rgb, +} + +fn deserialize_color_index<'a, D>(deserializer: D) -> ::std::result::Result<u8, D::Error> where D: de::Deserializer<'a> { - match CursorOrPrimaryColors::deserialize(deserializer) { - Ok(either) => Ok(either.into_cursor_colors()), + match u8::deserialize(deserializer) { + Ok(index) => { + if index < 16 { + eprintln!( + "problem with config: indexed_color's index is '{}', \ + but a value bigger than 15 was expected; \ + Ignoring setting", + index + ); + + // Return value out of range to ignore this color + Ok(0) + } else { + Ok(index) + } + }, Err(err) => { - eprintln!("problem with config: {}; Using default value", err); - Ok(CursorColors::default()) + eprintln!("problem with config: {}; Ignoring setting", err); + + // Return value out of range to ignore this color + Ok(0) }, } } @@ -1169,6 +1195,18 @@ impl Default for CursorColors { } } +fn deserialize_cursor_colors<'a, D>(deserializer: D) -> ::std::result::Result<CursorColors, D::Error> + where D: de::Deserializer<'a> +{ + match CursorOrPrimaryColors::deserialize(deserializer) { + Ok(either) => Ok(either.into_cursor_colors()), + Err(err) => { + eprintln!("problem with config: {}; Using default value", err); + Ok(CursorColors::default()) + }, + } +} + #[derive(Debug, Deserialize)] pub struct PrimaryColors { #[serde(deserialize_with = "rgb_from_hex")] @@ -1234,6 +1272,7 @@ impl Default for Colors { white: Rgb {r: 0xff, g: 0xff, b: 0xff}, }, dim: None, + indexed_colors: Vec::new(), } } } |