Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate color for underlines #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ The default theme.toml can be found [here](https://github.com/helix-editor/helix
Each line in the theme file is specified as below:

```toml
key = { fg = "#ffffff", bg = "#000000", modifiers = ["bold", "italic"] }
key = { fg = "#ffffff", bg = "#000000", underline = "#ff0000", modifiers = ["bold", "italic", "undercurled"] }
```

where `key` represents what you want to style, `fg` specifies the foreground color, `bg` the background color, and `modifiers` is a list of style modifiers. `bg` and `modifiers` can be omitted to defer to the defaults.
where `key` represents what you want to style, `fg` specifies the foreground color, `bg` the background color, `underline` the underline color (only meaningful if an underline modifier is enabled), and `modifiers` is a list of style modifiers. `bg`, `underline` and `modifiers` can be omitted to defer to the defaults.

To specify only the foreground color:

Expand Down Expand Up @@ -77,17 +77,21 @@ The following values may be used as modifiers.

Less common modifiers might not be supported by your terminal emulator.

| Modifier |
| --- |
| `bold` |
| `dim` |
| `italic` |
| `underlined` |
| `slow_blink` |
| `rapid_blink` |
| `reversed` |
| `hidden` |
| `crossed_out` |
| Modifier |
| --- |
| `bold` |
| `dim` |
| `italic` |
| `underlined` |
| `undercurled` |
| `underdashed` |
| `underdotted` |
| `double-underlined` |
| `slow_blink` |
| `rapid_blink` |
| `reversed` |
| `hidden` |
| `crossed_out` |

### Scopes

Expand Down
8 changes: 7 additions & 1 deletion helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crossterm::{
execute, queue,
style::{
Attribute as CAttribute, Color as CColor, Print, SetAttribute, SetBackgroundColor,
SetForegroundColor,
SetForegroundColor, SetUnderlineColor,
},
terminal::{self, Clear, ClearType},
};
Expand Down Expand Up @@ -47,6 +47,7 @@ where
{
let mut fg = Color::Reset;
let mut bg = Color::Reset;
let mut underline = Color::Reset;
let mut modifier = Modifier::empty();
let mut last_pos: Option<(u16, u16)> = None;
for (x, y, cell) in content {
Expand All @@ -73,6 +74,11 @@ where
map_error(queue!(self.buffer, SetBackgroundColor(color)))?;
bg = cell.bg;
}
if cell.underline != underline {
let color = CColor::from(cell.underline);
map_error(queue!(self.buffer, SetUnderlineColor(color)))?;
underline = cell.underline;
}

map_error(queue!(self.buffer, Print(&cell.symbol)))?;
}
Expand Down
10 changes: 9 additions & 1 deletion helix-tui/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Cell {
pub symbol: String,
pub fg: Color,
pub bg: Color,
pub underline: Color,
pub modifier: Modifier,
}

Expand Down Expand Up @@ -44,6 +45,9 @@ impl Cell {
if let Some(c) = style.bg {
self.bg = c;
}
if let Some(c) = style.underline {
self.underline = c;
}
self.modifier.insert(style.add_modifier);
self.modifier.remove(style.sub_modifier);
self
Expand All @@ -53,6 +57,7 @@ impl Cell {
Style::default()
.fg(self.fg)
.bg(self.bg)
.underline(self.underline)
.add_modifier(self.modifier)
}

Expand All @@ -61,6 +66,7 @@ impl Cell {
self.symbol.push(' ');
self.fg = Color::Reset;
self.bg = Color::Reset;
self.underline = Color::Reset;
self.modifier = Modifier::empty();
}
}
Expand All @@ -71,6 +77,7 @@ impl Default for Cell {
symbol: " ".into(),
fg: Color::Reset,
bg: Color::Reset,
underline: Color::Reset,
modifier: Modifier::empty(),
}
}
Expand All @@ -97,7 +104,8 @@ impl Default for Cell {
/// symbol: String::from("r"),
/// fg: Color::Red,
/// bg: Color::White,
/// modifier: Modifier::empty()
/// underline: Color::Reset,
/// modifier: Modifier::empty(),
/// });
/// buf[(5, 0)].set_char('x');
/// assert_eq!(buf[(5, 0)].symbol, "x");
Expand Down
4 changes: 4 additions & 0 deletions helix-tui/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl<'a> Span<'a> {
/// style: Style {
/// fg: Some(Color::Yellow),
/// bg: Some(Color::Black),
/// underline: None,
/// add_modifier: Modifier::empty(),
/// sub_modifier: Modifier::empty(),
/// },
Expand All @@ -143,6 +144,7 @@ impl<'a> Span<'a> {
/// style: Style {
/// fg: Some(Color::Yellow),
/// bg: Some(Color::Black),
/// underline: None,
/// add_modifier: Modifier::empty(),
/// sub_modifier: Modifier::empty(),
/// },
Expand All @@ -152,6 +154,7 @@ impl<'a> Span<'a> {
/// style: Style {
/// fg: Some(Color::Yellow),
/// bg: Some(Color::Black),
/// underline: None,
/// add_modifier: Modifier::empty(),
/// sub_modifier: Modifier::empty(),
/// },
Expand All @@ -161,6 +164,7 @@ impl<'a> Span<'a> {
/// style: Style {
/// fg: Some(Color::Yellow),
/// bg: Some(Color::Black),
/// underline: None,
/// add_modifier: Modifier::empty(),
/// sub_modifier: Modifier::empty(),
/// },
Expand Down
21 changes: 21 additions & 0 deletions helix-view/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl FromStr for Modifier {
/// Style {
/// fg: Some(Color::Yellow),
/// bg: Some(Color::Red),
/// underline: Some(Color::Reset),
/// add_modifier: Modifier::BOLD,
/// sub_modifier: Modifier::empty(),
/// },
Expand All @@ -429,6 +430,7 @@ impl FromStr for Modifier {
/// Style {
/// fg: Some(Color::Yellow),
/// bg: Some(Color::Reset),
/// underline: Some(Color::Reset),
/// add_modifier: Modifier::empty(),
/// sub_modifier: Modifier::empty(),
/// },
Expand All @@ -440,6 +442,7 @@ impl FromStr for Modifier {
pub struct Style {
pub fg: Option<Color>,
pub bg: Option<Color>,
pub underline: Option<Color>,
pub add_modifier: Modifier,
pub sub_modifier: Modifier,
}
Expand All @@ -449,6 +452,7 @@ impl Default for Style {
Style {
fg: None,
bg: None,
underline: None,
add_modifier: Modifier::empty(),
sub_modifier: Modifier::empty(),
}
Expand All @@ -461,6 +465,7 @@ impl Style {
Style {
fg: Some(Color::Reset),
bg: Some(Color::Reset),
underline: Some(Color::Reset),
add_modifier: Modifier::empty(),
sub_modifier: Modifier::all(),
}
Expand Down Expand Up @@ -496,6 +501,21 @@ impl Style {
self
}

/// Changes the underline color.
///
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::{Color, Style};
/// let style = Style::default().underline(Color::Blue);
/// let diff = Style::default().underline(Color::Red);
/// assert_eq!(style.patch(diff), Style::default().underline(Color::Red));
/// ```
pub fn underline(mut self, color: Color) -> Style {
self.underline = Some(color);
self
}

/// Changes the text emphasis.
///
/// When applied, it adds the given modifier to the `Style` modifiers.
Expand Down Expand Up @@ -552,6 +572,7 @@ impl Style {
pub fn patch(mut self, other: Style) -> Style {
self.fg = other.fg.or(self.fg);
self.bg = other.bg.or(self.bg);
self.underline = other.underline.or(self.underline);

self.add_modifier.remove(other.sub_modifier);
self.add_modifier.insert(other.add_modifier);
Expand Down
1 change: 1 addition & 0 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ impl ThemePalette {
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)?),
"modifiers" => {
let modifiers = value
.as_array()
Expand Down
3 changes: 2 additions & 1 deletion runtime/themes/dark_plus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"info" = { fg = "light_blue" }
"hint" = { fg = "light_gray3" }

diagnostic = { modifiers = ["underlined"] }
"diagnostic.error" = {underline = "red", modifiers = ["undercurled"] }
"diagnostic" = {underline = "gold", modifiers = ["undercurled"] }

[palette]
white = "#ffffff"
Expand Down