aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/theme.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-10-19 04:51:13 +0000
committerGitHub2022-10-19 04:51:13 +0000
commit418a622db9d957d09e10ccbc3897d8ac9268dc8e (patch)
tree6e69857287580ab24c1e60ac199138ac23dc37df /helix-view/src/theme.rs
parentfaf0c521d15c314f411cc6178024c5d3310212da (diff)
parent66a49080bc7e492c37f9cd10ed36a696de1787a3 (diff)
Merge pull request #4061 from pascalkuthe/undercurl-modifier
Support different kinds of underline rendering (updated)
Diffstat (limited to 'helix-view/src/theme.rs')
-rw-r--r--helix-view/src/theme.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs
index 8a1f8b7e..302844b7 100644
--- a/helix-view/src/theme.rs
+++ b/helix-view/src/theme.rs
@@ -11,6 +11,7 @@ use once_cell::sync::Lazy;
use serde::{Deserialize, Deserializer};
use toml::{map::Map, Value};
+use crate::graphics::UnderlineStyle;
pub use crate::graphics::{Color, Modifier, Style};
pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
@@ -378,19 +379,48 @@ impl ThemePalette {
.ok_or(format!("Theme: invalid modifier: {}", value))
}
+ pub fn parse_underline_style(value: &Value) -> Result<UnderlineStyle, String> {
+ value
+ .as_str()
+ .and_then(|s| s.parse().ok())
+ .ok_or(format!("Theme: invalid underline style: {}", value))
+ }
+
pub fn parse_style(&self, style: &mut Style, value: Value) -> Result<(), String> {
if let Value::Table(entries) = value {
- for (name, value) in entries {
+ for (name, mut value) in entries {
match name.as_str() {
"fg" => *style = style.fg(self.parse_color(value)?),
"bg" => *style = style.bg(self.parse_color(value)?),
+ "underline" => {
+ let table = value
+ .as_table_mut()
+ .ok_or("Theme: underline must be table")?;
+ if let Some(value) = table.remove("color") {
+ *style = style.underline_color(self.parse_color(value)?);
+ }
+ if let Some(value) = table.remove("style") {
+ *style = style.underline_style(Self::parse_underline_style(&value)?);
+ }
+
+ if let Some(attr) = table.keys().next() {
+ return Err(format!("Theme: invalid underline attribute: {attr}"));
+ }
+ }
"modifiers" => {
let modifiers = value
.as_array()
.ok_or("Theme: modifiers should be an array")?;
for modifier in modifiers {
- *style = style.add_modifier(Self::parse_modifier(modifier)?);
+ if modifier
+ .as_str()
+ .map_or(false, |modifier| modifier == "underlined")
+ {
+ *style = style.underline_style(UnderlineStyle::Line);
+ } else {
+ *style = style.add_modifier(Self::parse_modifier(modifier)?);
+ }
}
}
_ => return Err(format!("Theme: invalid style attribute: {}", name)),