diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2020-06-06 01:31:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 22:31:57 +0000 |
commit | de3437bcd6ff9637e74840b17285faf533a8f0a9 (patch) | |
tree | 325d50e6b6b0ed078c2a902de14aef510c81c109 | |
parent | f99220f01553c6c9d36e1f4ce01c007f4d4d4cb5 (diff) | |
download | alacritty-de3437bcd6ff9637e74840b17285faf533a8f0a9.tar.gz alacritty-de3437bcd6ff9637e74840b17285faf533a8f0a9.zip |
Fix class and cursor thickness deserialization
Fixes #3820.
-rw-r--r-- | alacritty_terminal/src/config/mod.rs | 18 | ||||
-rw-r--r-- | alacritty_terminal/src/config/window.rs | 62 |
2 files changed, 56 insertions, 24 deletions
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs index b3f13492..e41d7144 100644 --- a/alacritty_terminal/src/config/mod.rs +++ b/alacritty_terminal/src/config/mod.rs @@ -277,12 +277,24 @@ impl Default for Cursor { } } -pub fn deserialize_cursor_thickness<'a, D>(deserializer: D) -> Result<Percentage, D::Error> +fn deserialize_cursor_thickness<'a, D>(deserializer: D) -> Result<Percentage, D::Error> where D: Deserializer<'a>, { - Ok(Percentage::deserialize(Value::deserialize(deserializer)?) - .unwrap_or_else(|_| Percentage::new(DEFAULT_CURSOR_THICKNESS))) + let value = Value::deserialize(deserializer)?; + match Percentage::deserialize(value) { + Ok(value) => Ok(value), + Err(err) => { + error!( + target: LOG_TARGET_CONFIG, + "Problem with config: {}, using default thickness value {}", + err, + DEFAULT_CURSOR_THICKNESS + ); + + Ok(Percentage::new(DEFAULT_CURSOR_THICKNESS)) + }, + } } #[serde(untagged)] diff --git a/alacritty_terminal/src/config/window.rs b/alacritty_terminal/src/config/window.rs index f4405396..b410f0a2 100644 --- a/alacritty_terminal/src/config/window.rs +++ b/alacritty_terminal/src/config/window.rs @@ -42,7 +42,7 @@ pub struct WindowConfig { pub title: String, /// Window class. - #[serde(deserialize_with = "failure_default")] + #[serde(deserialize_with = "deserialize_class")] pub class: Class, /// XEmbed parent. @@ -158,9 +158,13 @@ impl Dimensions { } /// Window class hint. -#[derive(Debug, Clone, PartialEq, Eq)] +#[serde(default)] +#[derive(Deserialize, Debug, Clone, PartialEq, Eq)] pub struct Class { + #[serde(deserialize_with = "deserialize_class_resource")] pub instance: String, + + #[serde(deserialize_with = "deserialize_class_resource")] pub general: String, } @@ -170,26 +174,42 @@ impl Default for Class { } } -impl<'a> Deserialize<'a> for Class { - fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> - where - D: Deserializer<'a>, - { - let value = Value::deserialize(deserializer)?; +fn deserialize_class_resource<'a, D>(deserializer: D) -> Result<String, D::Error> +where + D: Deserializer<'a>, +{ + let value = Value::deserialize(deserializer)?; + match String::deserialize(value) { + Ok(value) => Ok(value), + Err(err) => { + error!( + target: LOG_TARGET_CONFIG, + "Problem with config: {}, using default value {}", err, DEFAULT_NAME, + ); + + Ok(DEFAULT_NAME.into()) + }, + } +} + +fn deserialize_class<'a, D>(deserializer: D) -> Result<Class, D::Error> +where + D: Deserializer<'a>, +{ + let value = Value::deserialize(deserializer)?; - if let Value::String(instance) = value { - return Ok(Class { instance, general: DEFAULT_NAME.into() }); - } + if let Value::String(instance) = value { + return Ok(Class { instance, general: DEFAULT_NAME.into() }); + } - match Self::deserialize(value) { - Ok(value) => Ok(value), - Err(err) => { - error!( - target: LOG_TARGET_CONFIG, - "Problem with config: {}; using class Alacritty", err - ); - Ok(Self::default()) - }, - } + match Class::deserialize(value) { + Ok(value) => Ok(value), + Err(err) => { + error!( + target: LOG_TARGET_CONFIG, + "Problem with config: {}; using class {}", err, DEFAULT_NAME + ); + Ok(Class::default()) + }, } } |