Skip to content

Commit

Permalink
Add theme key for selected line number
Browse files Browse the repository at this point in the history
Adds `ui.linenr.selected` which controls highlight of linu numbes which
have cursors on.

- Fallback to linenr if linenr.selected is missing

- Update docs and themes
  • Loading branch information
sudormrfbin committed Jun 15, 2021
1 parent 002f1ad commit b2a0ee4
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 38 deletions.
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Possible keys:
| module | |
| ui.background | |
| ui.linenr | |
| ui.linenr.selected | For lines with cursors |
| ui.statusline | |
| ui.popup | |
| ui.window | |
Expand Down
1 change: 1 addition & 0 deletions contrib/themes/bogster.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

"ui.background" = { bg = "#161c23" }
"ui.linenr" = { fg = "#415367" }
"ui.linenr.selected" = { fg = "#e5ded6" }
"ui.statusline" = { bg = "#232d38" }
"ui.popup" = { bg = "#232d38" }
"ui.window" = { bg = "#232d38" }
Expand Down
1 change: 1 addition & 0 deletions contrib/themes/ingrid.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

"ui.background" = { bg = "#FFFCFD" }
"ui.linenr" = { fg = "#bbbbbb" }
"ui.linenr.selected" = { fg = "#F3EAE9" }
"ui.statusline" = { bg = "#F3EAE9" }
"ui.popup" = { bg = "#F3EAE9" }
"ui.window" = { bg = "#D8B8B3" }
Expand Down
1 change: 1 addition & 0 deletions contrib/themes/onedark.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ui.background" = { fg = "#ABB2BF", bg = "#282C34" }
"ui.help" = { bg = "#3E4452" }
"ui.linenr" = { fg = "#4B5263", modifiers = ['dim'] }
"ui.linenr.selected" = { fg = "#ABB2BF" }
"ui.popup" = { bg = "#3E4452" }
"ui.statusline" = { fg = "#ABB2BF", bg = "#2C323C" }
"ui.selection" = { bg = "#3E4452" }
Expand Down
81 changes: 46 additions & 35 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,45 @@ impl EditorView {
}
}

// render selections
// render gutters

let linenr: Style = theme.get("ui.linenr");
let warning: Style = theme.get("warning");
let error: Style = theme.get("error");
let info: Style = theme.get("info");
let hint: Style = theme.get("hint");

for (i, line) in (view.first_line..last_line).enumerate() {
use helix_core::diagnostic::Severity;
if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
surface.set_stringn(
viewport.x - OFFSET,
viewport.y + i as u16,
"●",
1,
match diagnostic.severity {
Some(Severity::Error) => error,
Some(Severity::Warning) | None => warning,
Some(Severity::Info) => info,
Some(Severity::Hint) => hint,
},
);
}

// line numbers having selections are rendered differently
surface.set_stringn(
viewport.x + 1 - OFFSET,
viewport.y + i as u16,
format!("{:>5}", line + 1),
5,
linenr,
);
}

// render selections and selected linenr(s)
let linenr_select: Style = theme
.try_get("ui.linenr.selected")
.unwrap_or_else(|| theme.get("ui.linenr"));

if is_focused {
let screen = {
Expand Down Expand Up @@ -328,6 +366,13 @@ impl EditorView {
),
cursor_style,
);
surface.set_stringn(
viewport.x + 1 - OFFSET,
viewport.y + head.row as u16,
format!("{:>5}", view.first_line + head.row + 1),
5,
linenr_select,
);
// TODO: set cursor position for IME
if let Some(syntax) = doc.syntax() {
use helix_core::match_brackets;
Expand Down Expand Up @@ -356,40 +401,6 @@ impl EditorView {
}
}
}

// render gutters

let style: Style = theme.get("ui.linenr");
let warning: Style = theme.get("warning");
let error: Style = theme.get("error");
let info: Style = theme.get("info");
let hint: Style = theme.get("hint");

for (i, line) in (view.first_line..last_line).enumerate() {
use helix_core::diagnostic::Severity;
if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
surface.set_stringn(
viewport.x - OFFSET,
viewport.y + i as u16,
"●",
1,
match diagnostic.severity {
Some(Severity::Error) => error,
Some(Severity::Warning) | None => warning,
Some(Severity::Info) => info,
Some(Severity::Hint) => hint,
},
);
}

surface.set_stringn(
viewport.x + 1 - OFFSET,
viewport.y + i as u16,
format!("{:>5}", line + 1),
5,
style,
);
}
}

pub fn render_diagnostics(
Expand Down
8 changes: 5 additions & 3 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,14 @@ fn parse_modifier(value: &Value) -> Option<Modifier> {

impl Theme {
pub fn get(&self, scope: &str) -> Style {
self.styles
.get(scope)
.copied()
self.try_get(scope)
.unwrap_or_else(|| Style::default().fg(Color::Rgb(0, 0, 255)))
}

pub fn try_get(&self, scope: &str) -> Option<Style> {
self.styles.get(scope).copied()
}

#[inline]
pub fn scopes(&self) -> &[String] {
&self.scopes
Expand Down
1 change: 1 addition & 0 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

"ui.background" = { bg = "#3b224c" } # midnight
"ui.linenr" = { fg = "#5a5977" } # comet
"ui.linenr.selected" = { fg = "#dbbfef" } # lilac
"ui.statusline" = { bg = "#281733" } # revolver
"ui.popup" = { bg = "#281733" } # revolver
"ui.window" = { bg = "#452859" } # bossa nova
Expand Down

0 comments on commit b2a0ee4

Please sign in to comment.