aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/theme.rs
diff options
context:
space:
mode:
authorPascal Kuthe2022-10-01 00:15:25 +0000
committerPascal Kuthe2022-10-01 17:29:46 +0000
commit71ee589bbc723e7a55585ddc2ca43c29ee93fabe (patch)
treef64805cc305349a2430cae837355e7ef6ee7546c /helix-view/src/theme.rs
parent79d3d44c3db48365597eefd274e868bc1e15de57 (diff)
make underline_style a seperate option
Underline styles are mutally exclusive and overwrite each other. Therefore implementing as an modifier lead to incorrect behaviour when the underline style is overwritten. For backwards compatability the "underline" modified is retained (but deprecated). Instead the "underline_style" and "underline_color" optios should be used to style underlines.
Diffstat (limited to 'helix-view/src/theme.rs')
-rw-r--r--helix-view/src/theme.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs
index 5ce1b2c5..90185937 100644
--- a/helix-view/src/theme.rs
+++ b/helix-view/src/theme.rs
@@ -10,6 +10,7 @@ use once_cell::sync::Lazy;
use serde::{Deserialize, Deserializer};
use toml::Value;
+use crate::graphics::UnderlineStyle;
pub use crate::graphics::{Color, Modifier, Style};
pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
@@ -263,20 +264,38 @@ 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 {
match name.as_str() {
"fg" => *style = style.fg(self.parse_color(value)?),
"bg" => *style = style.bg(self.parse_color(value)?),
- "underline" => *style = style.underline(self.parse_color(value)?),
+ "underline_color" => *style = style.underline_color(self.parse_color(value)?),
+ "underline_style" => {
+ warn!("found style");
+ *style = style.underline_style(Self::parse_underline_style(&value)?)
+ }
"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)),