Skip to content

Commit d64b9ab

Browse files
committed
Support different kinds of underline rendering
Adds four new modifiers that can be used in themes: - undercurled - underdashed - underdotted - double-underline
1 parent b7a3531 commit d64b9ab

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

helix-tui/src/backend/crossterm.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl ModifierDiff {
153153
if removed.contains(Modifier::ITALIC) {
154154
map_error(queue!(w, SetAttribute(CAttribute::NoItalic)))?;
155155
}
156-
if removed.contains(Modifier::UNDERLINED) {
156+
if removed.intersects(Modifier::ANY_UNDERLINE) {
157157
map_error(queue!(w, SetAttribute(CAttribute::NoUnderline)))?;
158158
}
159159
if removed.contains(Modifier::DIM) {
@@ -179,6 +179,18 @@ impl ModifierDiff {
179179
if added.contains(Modifier::UNDERLINED) {
180180
map_error(queue!(w, SetAttribute(CAttribute::Underlined)))?;
181181
}
182+
if added.contains(Modifier::UNDERCURLED) {
183+
map_error(queue!(w, SetAttribute(CAttribute::Undercurled)))?;
184+
}
185+
if added.contains(Modifier::UNDERDOTTED) {
186+
map_error(queue!(w, SetAttribute(CAttribute::Underdotted)))?;
187+
}
188+
if added.contains(Modifier::UNDERDASHED) {
189+
map_error(queue!(w, SetAttribute(CAttribute::Underdashed)))?;
190+
}
191+
if added.contains(Modifier::DOUBLE_UNDERLINED) {
192+
map_error(queue!(w, SetAttribute(CAttribute::DoubleUnderlined)))?;
193+
}
182194
if added.contains(Modifier::DIM) {
183195
map_error(queue!(w, SetAttribute(CAttribute::Dim)))?;
184196
}

helix-view/src/graphics.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,27 @@ bitflags! {
327327
///
328328
/// let m = Modifier::BOLD | Modifier::ITALIC;
329329
/// ```
330-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
330+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "kebab-case"))]
331331
pub struct Modifier: u16 {
332-
const BOLD = 0b0000_0000_0001;
333-
const DIM = 0b0000_0000_0010;
334-
const ITALIC = 0b0000_0000_0100;
335-
const UNDERLINED = 0b0000_0000_1000;
336-
const SLOW_BLINK = 0b0000_0001_0000;
337-
const RAPID_BLINK = 0b0000_0010_0000;
338-
const REVERSED = 0b0000_0100_0000;
339-
const HIDDEN = 0b0000_1000_0000;
340-
const CROSSED_OUT = 0b0001_0000_0000;
332+
const BOLD = 0b0000_0000_0000_0001;
333+
const DIM = 0b0000_0000_0000_0010;
334+
const ITALIC = 0b0000_0000_0000_0100;
335+
const UNDERLINED = 0b0000_0000_0000_1000;
336+
const SLOW_BLINK = 0b0000_0000_0001_0000;
337+
const RAPID_BLINK = 0b0000_0000_0010_0000;
338+
const REVERSED = 0b0000_0000_0100_0000;
339+
const HIDDEN = 0b0000_0000_1000_0000;
340+
const CROSSED_OUT = 0b0000_0001_0000_0000;
341+
const UNDERCURLED = 0b0000_0010_0000_0000;
342+
const UNDERDOTTED = 0b0000_0100_0000_0000;
343+
const UNDERDASHED = 0b0000_1000_0000_0000;
344+
const DOUBLE_UNDERLINED = 0b0001_0000_0000_0000;
345+
346+
const ANY_UNDERLINE = Self::UNDERLINED.bits
347+
| Self::UNDERCURLED.bits
348+
| Self::UNDERDOTTED.bits
349+
| Self::UNDERDASHED.bits
350+
| Self::DOUBLE_UNDERLINED.bits;
341351
}
342352
}
343353

@@ -355,6 +365,10 @@ impl FromStr for Modifier {
355365
"reversed" => Ok(Self::REVERSED),
356366
"hidden" => Ok(Self::HIDDEN),
357367
"crossed_out" => Ok(Self::CROSSED_OUT),
368+
"undercurled" => Ok(Self::UNDERCURLED),
369+
"underdotted" => Ok(Self::UNDERDOTTED),
370+
"underdashed" => Ok(Self::UNDERDASHED),
371+
"double_underlined" => Ok(Self::DOUBLE_UNDERLINED),
358372
_ => Err("Invalid modifier"),
359373
}
360374
}

runtime/themes/onedark.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"diff.delta" = "gold"
4141
"diff.minus" = "red"
4242

43-
diagnostic = { modifiers = ["underlined"] }
43+
diagnostic = { modifiers = ["undercurled"] }
4444
"info" = { fg = "blue", modifiers = ["bold"] }
4545
"hint" = { fg = "green", modifiers = ["bold"] }
4646
"warning" = { fg = "yellow", modifiers = ["bold"] }

0 commit comments

Comments
 (0)