Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse hex colors in themes (#647) #889

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 17 additions & 3 deletions src/theme/color.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>
Expand Down Expand Up @@ -470,6 +469,21 @@ tree-edge: 245
assert_eq!(empty_theme, theme);
}

#[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
Expand Down
Loading