on master help sign in
Add separate color for underlines
3ad7d54A-Walrus
helix-tui/src/backend/crossterm.rs+7−1
@@ -4,7 +4,7 @@ use crossterm::{
4 execute, queue,
4 execute, queue,
5 style::{
5 style::{
6 Attribute as CAttribute, Color as CColor, Print, SetAttribute, SetBackgroundColor,
6 Attribute as CAttribute, Color as CColor, Print, SetAttribute, SetBackgroundColor,
7− SetForegroundColor,
7+ SetForegroundColor, SetUnderlineColor,
8 },
8 },
9 terminal::{self, Clear, ClearType},
9 terminal::{self, Clear, ClearType},
10};
10};
@@ -47,6 +47,7 @@ where
47 {
47 {
48 let mut fg = Color::Reset;
48 let mut fg = Color::Reset;
49 let mut bg = Color::Reset;
49 let mut bg = Color::Reset;
50+ let mut underline = Color::Reset;
50 let mut modifier = Modifier::empty();
51 let mut modifier = Modifier::empty();
51 let mut last_pos: Option<(u16, u16)> = None;
52 let mut last_pos: Option<(u16, u16)> = None;
52 for (x, y, cell) in content {
53 for (x, y, cell) in content {
@@ -73,6 +74,11 @@ where
73 map_error(queue!(self.buffer, SetBackgroundColor(color)))?;
74 map_error(queue!(self.buffer, SetBackgroundColor(color)))?;
74 bg = cell.bg;
75 bg = cell.bg;
75 }
76 }
77+ if cell.underline != underline {
78+ let color = CColor::from(cell.underline);
79+ map_error(queue!(self.buffer, SetUnderlineColor(color)))?;
80+ underline = cell.underline;
81+ }
76
82
77 map_error(queue!(self.buffer, Print(&cell.symbol)))?;
83 map_error(queue!(self.buffer, Print(&cell.symbol)))?;
78 }
84 }
helix-tui/src/buffer.rs+7
@@ -11,6 +11,7 @@ pub struct Cell {
11 pub symbol: String,
11 pub symbol: String,
12 pub fg: Color,
12 pub fg: Color,
13 pub bg: Color,
13 pub bg: Color,
14+ pub underline: Color,
14 pub modifier: Modifier,
15 pub modifier: Modifier,
15}
16}
16
17
@@ -44,6 +45,9 @@ impl Cell {
44 if let Some(c) = style.bg {
45 if let Some(c) = style.bg {
45 self.bg = c;
46 self.bg = c;
46 }
47 }
48+ if let Some(c) = style.underline {
49+ self.underline = c;
50+ }
47 self.modifier.insert(style.add_modifier);
51 self.modifier.insert(style.add_modifier);
48 self.modifier.remove(style.sub_modifier);
52 self.modifier.remove(style.sub_modifier);
49 self
53 self
@@ -53,6 +57,7 @@ impl Cell {
53 Style::default()
57 Style::default()
54 .fg(self.fg)
58 .fg(self.fg)
55 .bg(self.bg)
59 .bg(self.bg)
60+ .underline(self.bg)
56 .add_modifier(self.modifier)
61 .add_modifier(self.modifier)
57 }
62 }
58
63
@@ -61,6 +66,7 @@ impl Cell {
61 self.symbol.push(' ');
66 self.symbol.push(' ');
62 self.fg = Color::Reset;
67 self.fg = Color::Reset;
63 self.bg = Color::Reset;
68 self.bg = Color::Reset;
69+ self.underline = Color::Reset;
64 self.modifier = Modifier::empty();
70 self.modifier = Modifier::empty();
65 }
71 }
66}
72}
@@ -71,6 +77,7 @@ impl Default for Cell {
71 symbol: " ".into(),
77 symbol: " ".into(),
72 fg: Color::Reset,
78 fg: Color::Reset,
73 bg: Color::Reset,
79 bg: Color::Reset,
80+ underline: Color::Reset,
74 modifier: Modifier::empty(),
81 modifier: Modifier::empty(),
75 }
82 }
76 }
83 }
helix-view/src/graphics.rs+19
@@ -440,6 +440,7 @@ impl FromStr for Modifier {
440pub struct Style {
440pub struct Style {
441 pub fg: Option<Color>,
441 pub fg: Option<Color>,
442 pub bg: Option<Color>,
442 pub bg: Option<Color>,
443+ pub underline: Option<Color>,
443 pub add_modifier: Modifier,
444 pub add_modifier: Modifier,
444 pub sub_modifier: Modifier,
445 pub sub_modifier: Modifier,
445}
446}
@@ -449,6 +450,7 @@ impl Default for Style {
449 Style {
450 Style {
450 fg: None,
451 fg: None,
451 bg: None,
452 bg: None,
453+ underline: None,
452 add_modifier: Modifier::empty(),
454 add_modifier: Modifier::empty(),
453 sub_modifier: Modifier::empty(),
455 sub_modifier: Modifier::empty(),
454 }
456 }
@@ -461,6 +463,7 @@ impl Style {
461 Style {
463 Style {
462 fg: Some(Color::Reset),
464 fg: Some(Color::Reset),
463 bg: Some(Color::Reset),
465 bg: Some(Color::Reset),
466+ underline: Some(Color::Reset),
464 add_modifier: Modifier::empty(),
467 add_modifier: Modifier::empty(),
465 sub_modifier: Modifier::all(),
468 sub_modifier: Modifier::all(),
466 }
469 }
@@ -496,6 +499,21 @@ impl Style {
496 self
499 self
497 }
500 }
498
501
502+ /// Changes the underline color.
503+ ///
504+ /// ## Examples
505+ ///
506+ /// ```rust
507+ /// # use helix_view::graphics::{Color, Style};
508+ /// let style = Style::default().underline(Color::Blue);
509+ /// let diff = Style::default().underline(Color::Red);
510+ /// assert_eq!(style.patch(diff), Style::default().underline(Color::Red));
511+ /// ```
512+ pub fn underline(mut self, color: Color) -> Style {
513+ self.underline = Some(color);
514+ self
515+ }
516+
499 /// Changes the text emphasis.
517 /// Changes the text emphasis.
500 ///
518 ///
501 /// When applied, it adds the given modifier to the `Style` modifiers.
519 /// When applied, it adds the given modifier to the `Style` modifiers.
@@ -552,6 +570,7 @@ impl Style {
552 pub fn patch(mut self, other: Style) -> Style {
570 pub fn patch(mut self, other: Style) -> Style {
553 self.fg = other.fg.or(self.fg);
571 self.fg = other.fg.or(self.fg);
554 self.bg = other.bg.or(self.bg);
572 self.bg = other.bg.or(self.bg);
573+ self.underline = other.underline.or(self.underline);
555
574
556 self.add_modifier.remove(other.sub_modifier);
575 self.add_modifier.remove(other.sub_modifier);
557 self.add_modifier.insert(other.add_modifier);
576 self.add_modifier.insert(other.add_modifier);
helix-view/src/theme.rs+1
@@ -269,6 +269,7 @@ impl ThemePalette {
269 match name.as_str() {
269 match name.as_str() {
270 "fg" => *style = style.fg(self.parse_color(value)?),
270 "fg" => *style = style.fg(self.parse_color(value)?),
271 "bg" => *style = style.bg(self.parse_color(value)?),
271 "bg" => *style = style.bg(self.parse_color(value)?),
272+ "underline" => *style = style.underline(self.parse_color(value)?),
272 "modifiers" => {
273 "modifiers" => {
273 let modifiers = value
274 let modifiers = value
274 .as_array()
275 .as_array()
runtime/themes/dark_plus.toml+2−1
@@ -92,7 +92,8 @@
92"info" = { fg = "light_blue" }
92"info" = { fg = "light_blue" }
93"hint" = { fg = "light_gray3" }
93"hint" = { fg = "light_gray3" }
94
94
95+"diagnostic.error" = {underline = "red", modifiers = ["undercurled"] }
95−diagnostic = { modifiers = ["underlined"] }
96+"diagnostic" = {underline = "gold", modifiers = ["undercurled"] }
96
97
97[palette]
98[palette]
98white = "#ffffff"
99white = "#ffffff"