summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--Cargo.lock33
-rw-r--r--Cargo.toml2
-rw-r--r--src/theme/color.rs20
3 files changed, 39 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 614a722..7ae7586 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -61,6 +61,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
+name = "bitflags"
+version = "2.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
+dependencies = [
+ "serde",
+]
+
+[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -121,7 +130,7 @@ version = "4.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
"clap_derive",
"clap_lex",
"is-terminal",
@@ -174,11 +183,11 @@ dependencies = [
[[package]]
name = "crossterm"
-version = "0.24.0"
+version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab9f7409c70a38a56216480fba371ee460207dd8926ccf5b4160591759559170"
+checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df"
dependencies = [
- "bitflags",
+ "bitflags 2.4.0",
"crossterm_winapi",
"libc",
"mio",
@@ -191,9 +200,9 @@ dependencies = [
[[package]]
name = "crossterm_winapi"
-version = "0.9.0"
+version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c"
+checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]
@@ -304,7 +313,7 @@ version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
"libc",
"libgit2-sys",
"log",
@@ -336,7 +345,7 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
"ignore",
"walkdir",
]
@@ -794,7 +803,7 @@ version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
]
[[package]]
@@ -846,7 +855,7 @@ version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03"
dependencies = [
- "bitflags",
+ "bitflags 1.3.2",
"errno",
"io-lifetimes",
"libc",
@@ -931,9 +940,9 @@ dependencies = [
[[package]]
name = "signal-hook"
-version = "0.3.14"
+version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d"
+checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801"
dependencies = [
"libc",
"signal-hook-registry",
diff --git a/Cargo.toml b/Cargo.toml
index 30fa892..11b5986 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,7 @@ clap_complete = "4.1"
version_check = "0.9.*"
[dependencies]
-crossterm = { version = "0.24.0", features = ["serde"] }
+crossterm = { version = "0.27.0", features = ["serde"] }
dirs = "3.0.*"
libc = "0.2.*"
human-sort = "0.2.2"
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