on master help sign in
Add separate color for underlines
commit3ad7d543ca17963f0839b1a6cd8abacdb5c60cf7 authorA-Walrus <ofek.r.guy@gmail.com> dateThu 11 Aug 2022, 14:10 (4 years ago) parent999b45b
5 files changed+36−2
helix-tui/src/backend/crossterm.rs+7−1 helix-tui/src/buffer.rs+7 helix-view/src/graphics.rs+19 helix-view/src/theme.rs+1 runtime/themes/dark_plus.toml+2−1
helix-tui/src/backend/crossterm.rs+7−1
@@ -4,7 +4,7 @@ use crossterm::{
44 execute, queue,
55 style::{
66 Attribute as CAttribute, Color as CColor, Print, SetAttribute, SetBackgroundColor,
7− SetForegroundColor,
7+ SetForegroundColor, SetUnderlineColor,
88 },
99 terminal::{self, Clear, ClearType},
1010};
@@ -47,6 +47,7 @@ where
4747 {
4848 let mut fg = Color::Reset;
4949 let mut bg = Color::Reset;
50+ let mut underline = Color::Reset;
5051 let mut modifier = Modifier::empty();
5152 let mut last_pos: Option<(u16, u16)> = None;
5253 for (x, y, cell) in content {
@@ -73,6 +74,11 @@ where
7374 map_error(queue!(self.buffer, SetBackgroundColor(color)))?;
7475 bg = cell.bg;
7576 }
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+ }
7682
7783 map_error(queue!(self.buffer, Print(&cell.symbol)))?;
7884 }
helix-tui/src/buffer.rs+7
@@ -11,6 +11,7 @@ pub struct Cell {
1111 pub symbol: String,
1212 pub fg: Color,
1313 pub bg: Color,
14+ pub underline: Color,
1415 pub modifier: Modifier,
1516}
1617
@@ -44,6 +45,9 @@ impl Cell {
4445 if let Some(c) = style.bg {
4546 self.bg = c;
4647 }
48+ if let Some(c) = style.underline {
49+ self.underline = c;
50+ }
4751 self.modifier.insert(style.add_modifier);
4852 self.modifier.remove(style.sub_modifier);
4953 self
@@ -53,6 +57,7 @@ impl Cell {
5357 Style::default()
5458 .fg(self.fg)
5559 .bg(self.bg)
60+ .underline(self.bg)
5661 .add_modifier(self.modifier)
5762 }
5863
@@ -61,6 +66,7 @@ impl Cell {
6166 self.symbol.push(' ');
6267 self.fg = Color::Reset;
6368 self.bg = Color::Reset;
69+ self.underline = Color::Reset;
6470 self.modifier = Modifier::empty();
6571 }
6672}
@@ -71,6 +77,7 @@ impl Default for Cell {
7177 symbol: " ".into(),
7278 fg: Color::Reset,
7379 bg: Color::Reset,
80+ underline: Color::Reset,
7481 modifier: Modifier::empty(),
7582 }
7683 }
helix-view/src/graphics.rs+19
@@ -440,6 +440,7 @@ impl FromStr for Modifier {
440440pub struct Style {
441441 pub fg: Option<Color>,
442442 pub bg: Option<Color>,
443+ pub underline: Option<Color>,
443444 pub add_modifier: Modifier,
444445 pub sub_modifier: Modifier,
445446}
@@ -449,6 +450,7 @@ impl Default for Style {
449450 Style {
450451 fg: None,
451452 bg: None,
453+ underline: None,
452454 add_modifier: Modifier::empty(),
453455 sub_modifier: Modifier::empty(),
454456 }
@@ -461,6 +463,7 @@ impl Style {
461463 Style {
462464 fg: Some(Color::Reset),
463465 bg: Some(Color::Reset),
466+ underline: Some(Color::Reset),
464467 add_modifier: Modifier::empty(),
465468 sub_modifier: Modifier::all(),
466469 }
@@ -496,6 +499,21 @@ impl Style {
496499 self
497500 }
498501
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+
499517 /// Changes the text emphasis.
500518 ///
501519 /// When applied, it adds the given modifier to the `Style` modifiers.
@@ -552,6 +570,7 @@ impl Style {
552570 pub fn patch(mut self, other: Style) -> Style {
553571 self.fg = other.fg.or(self.fg);
554572 self.bg = other.bg.or(self.bg);
573+ self.underline = other.underline.or(self.underline);
555574
556575 self.add_modifier.remove(other.sub_modifier);
557576 self.add_modifier.insert(other.add_modifier);
helix-view/src/theme.rs+1
@@ -269,6 +269,7 @@ impl ThemePalette {
269269 match name.as_str() {
270270 "fg" => *style = style.fg(self.parse_color(value)?),
271271 "bg" => *style = style.bg(self.parse_color(value)?),
272+ "underline" => *style = style.underline(self.parse_color(value)?),
272273 "modifiers" => {
273274 let modifiers = value
274275 .as_array()
runtime/themes/dark_plus.toml+2−1
@@ -92,7 +92,8 @@
9292"info" = { fg = "light_blue" }
9393"hint" = { fg = "light_gray3" }
9494
95−diagnostic = { modifiers = ["underlined"] }
95+"diagnostic.error" = {underline = "red", modifiers = ["undercurled"] }
96+"diagnostic" = {underline = "gold", modifiers = ["undercurled"] }
9697
9798[palette]
9899white = "#ffffff"