Skip to content

Commit

Permalink
Support different kinds of underline rendering
Browse files Browse the repository at this point in the history
Adds four new  modifiers that can be used in themes:

- undercurled
- underdashed
- underdotted
- double-underline
  • Loading branch information
sudormrfbin authored and pascalkuthe committed Oct 1, 2022
1 parent c958425 commit 999b45b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
14 changes: 13 additions & 1 deletion helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl ModifierDiff {
if removed.contains(Modifier::ITALIC) {
map_error(queue!(w, SetAttribute(CAttribute::NoItalic)))?;
}
if removed.contains(Modifier::UNDERLINED) {
if removed.intersects(Modifier::ANY_UNDERLINE) {
map_error(queue!(w, SetAttribute(CAttribute::NoUnderline)))?;
}
if removed.contains(Modifier::DIM) {
Expand All @@ -179,6 +179,18 @@ impl ModifierDiff {
if added.contains(Modifier::UNDERLINED) {
map_error(queue!(w, SetAttribute(CAttribute::Underlined)))?;
}
if added.contains(Modifier::UNDERCURLED) {
map_error(queue!(w, SetAttribute(CAttribute::Undercurled)))?;
}
if added.contains(Modifier::UNDERDOTTED) {
map_error(queue!(w, SetAttribute(CAttribute::Underdotted)))?;
}
if added.contains(Modifier::UNDERDASHED) {
map_error(queue!(w, SetAttribute(CAttribute::Underdashed)))?;
}
if added.contains(Modifier::DOUBLE_UNDERLINED) {
map_error(queue!(w, SetAttribute(CAttribute::DoubleUnderlined)))?;
}
if added.contains(Modifier::DIM) {
map_error(queue!(w, SetAttribute(CAttribute::Dim)))?;
}
Expand Down
34 changes: 24 additions & 10 deletions helix-view/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,27 @@ bitflags! {
///
/// let m = Modifier::BOLD | Modifier::ITALIC;
/// ```
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "kebab-case"))]
pub struct Modifier: u16 {
const BOLD = 0b0000_0000_0001;
const DIM = 0b0000_0000_0010;
const ITALIC = 0b0000_0000_0100;
const UNDERLINED = 0b0000_0000_1000;
const SLOW_BLINK = 0b0000_0001_0000;
const RAPID_BLINK = 0b0000_0010_0000;
const REVERSED = 0b0000_0100_0000;
const HIDDEN = 0b0000_1000_0000;
const CROSSED_OUT = 0b0001_0000_0000;
const BOLD = 0b0000_0000_0000_0001;
const DIM = 0b0000_0000_0000_0010;
const ITALIC = 0b0000_0000_0000_0100;
const UNDERLINED = 0b0000_0000_0000_1000;
const SLOW_BLINK = 0b0000_0000_0001_0000;
const RAPID_BLINK = 0b0000_0000_0010_0000;
const REVERSED = 0b0000_0000_0100_0000;
const HIDDEN = 0b0000_0000_1000_0000;
const CROSSED_OUT = 0b0000_0001_0000_0000;
const UNDERCURLED = 0b0000_0010_0000_0000;
const UNDERDOTTED = 0b0000_0100_0000_0000;
const UNDERDASHED = 0b0000_1000_0000_0000;
const DOUBLE_UNDERLINED = 0b0001_0000_0000_0000;

const ANY_UNDERLINE = Self::UNDERLINED.bits
| Self::UNDERCURLED.bits
| Self::UNDERDOTTED.bits
| Self::UNDERDASHED.bits
| Self::DOUBLE_UNDERLINED.bits;
}
}

Expand All @@ -355,6 +365,10 @@ impl FromStr for Modifier {
"reversed" => Ok(Self::REVERSED),
"hidden" => Ok(Self::HIDDEN),
"crossed_out" => Ok(Self::CROSSED_OUT),
"undercurled" => Ok(Self::UNDERCURLED),
"underdotted" => Ok(Self::UNDERDOTTED),
"underdashed" => Ok(Self::UNDERDASHED),
"double_underlined" => Ok(Self::DOUBLE_UNDERLINED),
_ => Err("Invalid modifier"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/themes/onedark.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"diff.delta" = "gold"
"diff.minus" = "red"

diagnostic = { modifiers = ["underlined"] }
diagnostic = { modifiers = ["undercurled"] }
"info" = { fg = "blue", modifiers = ["bold"] }
"hint" = { fg = "green", modifiers = ["bold"] }
"warning" = { fg = "yellow", modifiers = ["bold"] }
Expand Down

0 comments on commit 999b45b

Please sign in to comment.