Skip to content

Commit

Permalink
Fix error type in xresources
Browse files Browse the repository at this point in the history
  • Loading branch information
jkorinth committed Apr 22, 2024
1 parent 570ff9a commit 4a636e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/themes/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ impl FromStr for Color {
Color::Hsva(Hsva::new(h, s / 100., v / 100., (a / 100. * 255.) as u8))
} else if color.starts_with("x:") {
let name = color.split_at(2).1;
let hex = super::xresources::get_color(name)
.map_err(|e| Self::Err::new(e))?
let hex = super::xresources::get_color(name)?
.ok_or_else(|| {
Self::Err::new(format!("color {} not defined in ~/.Xresources", name))
})?;
Expand Down
9 changes: 5 additions & 4 deletions src/themes/xresources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use log::debug;
use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::HashMap;
use crate::errors::Error;

#[cfg(not(test))]
use std::{env, path::PathBuf};
Expand All @@ -22,7 +23,7 @@ use tests::read_xresources;
static COLOR_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^\s*\*(?<name>[^: ]+)\s*:\s*(?<color>#[a-f0-9]{6}).*$").unwrap());

static COLORS: Lazy<Result<HashMap<String, String>, String>> =
static COLORS: Lazy<Result<HashMap<String, String>, Error>> =
Lazy::new(|| match read_xresources() {
Ok(content) => {
debug!(".Xresources content:\n{}", content);
Expand All @@ -37,11 +38,11 @@ static COLORS: Lazy<Result<HashMap<String, String>, String>> =
.flatten(),
));
}
Err(e) => Err(format!("could not read .Xresources: {}", e)),
Err(e) => Err(Error::new(format!("could not read .Xresources: {}", e))),
});

pub fn get_color(name: &str) -> Result<Option<&String>, String> {
Ok(COLORS.as_ref().map(|cmap| cmap.get(name))?)
pub fn get_color(name: &str) -> Result<Option<&String>, Error> {
Ok(COLORS.as_ref().map(|cmap| cmap.get(name)).map_err(Clone::clone)?)
}

#[cfg(test)]
Expand Down

0 comments on commit 4a636e2

Please sign in to comment.