From cd79680ba23b3d9c22372c95fa53dec5b4ea7c8e Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 23 Sep 2018 23:05:15 +0000 Subject: 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. --- src/config.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/config.rs') 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, + #[serde(default, deserialize_with = "failure_default_vec")] + pub indexed_colors: Vec, } -fn deserialize_cursor_colors<'a, D>(deserializer: D) -> ::std::result::Result +#[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 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 + 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(), } } } -- cgit