Skip to content

Commit

Permalink
CI massaging
Browse files Browse the repository at this point in the history
  • Loading branch information
jkorinth committed Apr 23, 2024
1 parent afa849b commit 1e132c3
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion doc/themes.md
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ All `bg` and `fg` overrides are either
* html hex color codes like `#000000` or `#789ABC`; a fourth byte for alpha (like `#acbdef42`) works on some systems. `00` is transparent, `FF` is opaque, or
* a reference to another override, e.g., `{ link = "idle-bg" }`, or
* a reference to a color name defined in `~/.Xresources`, e.g., `x:background` looks for a line like `*background: #aabbcc` in `~/.Xresources` (see also [.Xresources](https://wiki.debian.org/Xresources)).

The tints are added to every second block counting from the right. They will therefore always brighten the block and never darken it. The alpha channel, if it works, can also be alternated in the same way.

Feel free to take a look at the provided color schemes for reference.
6 changes: 2 additions & 4 deletions src/themes/color.rs
Original file line number Diff line number Diff line change
@@ -223,11 +223,9 @@ impl FromStr for Color {
let err_msg = || format!("'{name}' def '{hex}' cannot be parsed as RGB");
let rgb = hex
.get(1..7)
.map(|rgb| u32::from_str_radix(rgb, 16).ok())
.flatten();
.and_then(|rgb| u32::from_str_radix(rgb, 16).ok());
let a = u32::from_str_radix(hex.get(7..9).unwrap_or("FF"), 16).ok();
rgb.map(|rgb| a.map(|a| Color::Rgba(Rgba::from_hex((rgb << 8) + a))))
.flatten()
rgb.and_then(|rgb| a.map(|a| Color::Rgba(Rgba::from_hex((rgb << 8) + a))))
.or_error(err_msg)?
} else {
let err_msg = || format!("'{color}' is not a valid RGBA color");
22 changes: 10 additions & 12 deletions src/themes/xresources.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::errors::Error;
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};
@@ -27,22 +27,20 @@ static COLORS: Lazy<Result<HashMap<String, String>, Error>> =
Lazy::new(|| match read_xresources() {
Ok(content) => {
debug!(".Xresources content:\n{}", content);
return Ok(HashMap::from_iter(
content
.lines()
.map(|line| {
COLOR_REGEX
.captures(line)
.map(|caps| (caps["name"].to_string(), caps["color"].to_string()))
})
.flatten(),
));
return Ok(HashMap::from_iter(content.lines().filter_map(|line| {
COLOR_REGEX
.captures(line)
.map(|caps| (caps["name"].to_string(), caps["color"].to_string()))
})));
}
Err(e) => Err(Error::new(format!("could not read .Xresources: {}", e))),
});

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

#[cfg(test)]

0 comments on commit 1e132c3

Please sign in to comment.