Skip to content

Commit

Permalink
feat(debug): highlight current line
Browse files Browse the repository at this point in the history
Add new theme highlight keys, for setting the colour of the breakpoint
character and the current line at which execution has been
paused at. The two new keys are `ui.highlight.breakpoint` and
`ui.highlight.currentline`. Highlight according to those keys, both the
line at which debugging is paused at and the breakpoint indicator.

Better icons are dependent on helix-editor#2869, and as such will be handled in the
future, once it lands.

Closes: helix-editor#5952
Signed-off-by: Filip Dutescu <[email protected]>
  • Loading branch information
filipdutescu committed Feb 13, 2023
1 parent 2bebc50 commit 929e22f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ These scopes are used for theming the editor interface.
| `ui.cursor.primary.normal` | |
| `ui.cursor.primary.insert` | |
| `ui.cursor.primary.select` | |
| `ui.highlight.breakpoint` | Color of the breakpoint signal, found in the gutter. |
| `ui.highlight.currentline` | Color of the current line, at which debugging execution is paused at. |
| `ui.gutter` | Gutter |
| `ui.gutter.selected` | Gutter for the line the cursor is on |
| `ui.linenr` | Line numbers |
Expand Down
10 changes: 5 additions & 5 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,26 @@ impl EditorView {
.and_then(|source| source.path.as_ref())
== doc.path()
{
let line = frame.line - 1; // convert to 0-indexing
let style = theme.get("ui.highlight");
let line = frame.line;
let style = theme.get("ui.highlight.currentline");
let line_decoration = move |renderer: &mut TextRenderer, pos: LinePos| {
if pos.doc_line != line {
return;
}
renderer
.surface
.set_style(Rect::new(area.x, pos.visual_line, area.width, 1), style);
.set_style(Rect::new(inner.x, pos.visual_line, inner.width, 1), style);
};

line_decorations.push(Box::new(line_decoration));
}
}

if is_focused && config.cursorline {
if stack_frame.is_none() && is_focused && config.cursorline {
line_decorations.push(Self::cursorline_decorator(doc, view, theme))
}

if is_focused && config.cursorcolumn {
if stack_frame.is_none() && is_focused && config.cursorcolumn {
Self::highlight_cursorcolumn(doc, view, surface, theme, inner, &text_annotations);
}

Expand Down
14 changes: 7 additions & 7 deletions helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ pub fn breakpoints<'doc>(
theme: &Theme,
_is_focused: bool,
) -> GutterFn<'doc> {
let warning = theme.get("warning");
let error = theme.get("error");
let info = theme.get("info");
let breakpoint_style = theme.get("ui.highlight.breakpoint");

let breakpoints = doc.path().and_then(|path| editor.breakpoints.get(path));

Expand All @@ -272,23 +272,23 @@ pub fn breakpoints<'doc>(
} else if breakpoint.log_message.is_some() {
info
} else {
warning
breakpoint_style
};

if !breakpoint.verified {
// Faded colors
style = if let Some(Color::Rgb(r, g, b)) = style.fg {
style = if let Some(Color::Rgb(r, g, b)) = breakpoint_style.fg {
style.fg(Color::Rgb(
((r as f32) * 0.4).floor() as u8,
((g as f32) * 0.4).floor() as u8,
((b as f32) * 0.4).floor() as u8,
((r as f32) * 0.7).floor() as u8,
((g as f32) * 0.7).floor() as u8,
((b as f32) * 0.7).floor() as u8,
))
} else {
style.fg(Color::Gray)
}
};

let sym = if breakpoint.verified { "▲" } else { "⊚" };
let sym = "●";
write!(out, "{}", sym).unwrap();
Some(style)
},
Expand Down
2 changes: 2 additions & 0 deletions runtime/themes/dracula.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"ui.cursor.primary" = { fg = "background", bg = "cyan", modifiers = ["dim"] }
"ui.cursorline.primary" = { bg = "background_dark" }
"ui.help" = { fg = "foreground", bg = "background_dark" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.linenr" = { fg = "comment" }
"ui.linenr.selected" = { fg = "foreground" }
"ui.menu" = { fg = "foreground", bg = "background_dark" }
Expand Down
2 changes: 2 additions & 0 deletions runtime/themes/dracula_at_night.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"ui.cursor.match" = { fg = "green", modifiers = ["underlined"] }
"ui.cursor.primary" = { fg = "background", bg = "cyan", modifiers = ["dim"] }
"ui.help" = { fg = "foreground", bg = "background_dark" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.linenr" = { fg = "comment" }
"ui.linenr.selected" = { fg = "foreground" }
"ui.menu" = { fg = "foreground", bg = "background_dark" }
Expand Down
2 changes: 2 additions & 0 deletions runtime/themes/onedark.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"ui.text.focus" = { fg = "white", bg = "light-black", modifiers = ["bold"] }

"ui.help" = { fg = "white", bg = "gray" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.popup" = { bg = "gray" }
"ui.window" = { fg = "gray" }
"ui.menu" = { fg = "white", bg = "gray" }
Expand Down
2 changes: 2 additions & 0 deletions runtime/themes/onedarker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"ui.text.focus" = { fg = "white", bg = "light-black", modifiers = ["bold"] }

"ui.help" = { fg = "white", bg = "gray" }
"ui.highlight.breakpoint" = { fg = "red" }
"ui.highlight.currentline" = { fg = "black", bg = "red", modifiers = ["bold"] }
"ui.popup" = { bg = "gray" }
"ui.window" = { fg = "gray" }
"ui.menu" = { fg = "white", bg = "gray" }
Expand Down
2 changes: 2 additions & 0 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ label = "honey"
"ui.cursor" = { modifiers = ["reversed"] }
"ui.cursorline.primary" = { bg = "bossanova" }
"ui.highlight" = { bg = "bossanova" }
"ui.highlight.breakpoint" = { fg = "apricot" }
"ui.highlight.currentline" = { fg = "bossanova", bg = "apricot", modifiers = ["bold"] }

"ui.menu" = { fg = "lavender", bg = "revolver" }
"ui.menu.selected" = { fg = "revolver", bg = "white" }
Expand Down

0 comments on commit 929e22f

Please sign in to comment.