summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjoern Hiller <bjoern.hiller@gmail.com>2023-08-29 23:01:11 +0200
committerWei Zhang <kweizh@gmail.com>2023-08-30 12:21:18 +0800
commit7a9506da8974b469d9877c5a7a96b35907e5144a (patch)
treecc57e907ddbc3a019baf3c0535c394ffc118d424 /src
parent2fd1877417bf0e6a75cc56d1e48b756c30b3b275 (diff)
Parse hex colors in themes (#647)
Just delegate to the default deserializer of crossterm which learned dealing with hex color in version 0.27.0.
Diffstat (limited to 'src')
-rw-r--r--src/theme/color.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/theme/color.rs b/src/theme/color.rs
index 35b8712..337477e 100644
--- a/src/theme/color.rs
+++ b/src/theme/color.rs
@@ -1,7 +1,7 @@
///! This module provides methods to create theme from files and operations related to
///! this.
use crossterm::style::Color;
-use serde::Deserialize;
+use serde::{de::IntoDeserializer, Deserialize};
use std::fmt;
// Custom color deserialize
@@ -23,8 +23,7 @@ where
where
E: serde::de::Error,
{
- Color::try_from(value)
- .map_err(|_| E::invalid_value(serde::de::Unexpected::Str(value), &self))
+ Color::deserialize(value.into_deserializer())
}
fn visit_u64<E>(self, value: u64) -> Result<Color, E>
@@ -471,6 +470,21 @@ tree-edge: 245
}
#[test]
+ fn test_hexadecimal_colors() {
+ // Must contain one field at least
+ // ref https://github.com/dtolnay/serde-yaml/issues/86
+ let empty_theme: ColorTheme = Theme::with_yaml("user: \"#ff007f\"").unwrap();
+ assert_eq!(
+ empty_theme.user,
+ crossterm::style::Color::Rgb {
+ r: 255,
+ g: 0,
+ b: 127
+ }
+ );
+ }
+
+ #[test]
fn test_second_level_theme_return_default_but_changed() {
// Must contain one field at least
// ref https://github.com/dtolnay/serde-yaml/issues/86