aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGokul Soumya2021-06-14 14:01:17 +0000
committerBlaž Hrastnik2021-06-16 06:00:14 +0000
commitd1c8a74771b241ee0824853bd5e8229cb0ab4187 (patch)
tree583f5e890713384295c82930a1f531cf1a6693af
parent33a35b7589dbc35f43f8823b79591ca857bceeac (diff)
Add theme key for selected line number
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 - Add TODOs for themes with temporary linenr.selected
-rw-r--r--book/src/configuration.md1
-rw-r--r--contrib/themes/bogster.toml1
-rw-r--r--contrib/themes/ingrid.toml1
-rw-r--r--contrib/themes/onedark.toml1
-rw-r--r--helix-term/src/ui/editor.rs81
-rw-r--r--helix-view/src/theme.rs8
-rw-r--r--theme.toml1
7 files changed, 56 insertions, 38 deletions
diff --git a/book/src/configuration.md b/book/src/configuration.md
index 363279f2..649aa21f 100644
--- a/book/src/configuration.md
+++ b/book/src/configuration.md
@@ -70,6 +70,7 @@ Possible keys:
| `module` | |
| `ui.background` | |
| `ui.linenr` | |
+| `ui.linenr.selected` | For lines with cursors |
| `ui.statusline` | |
| `ui.popup` | |
| `ui.window` | |
diff --git a/contrib/themes/bogster.toml b/contrib/themes/bogster.toml
index 0fbafd23..205e464c 100644
--- a/contrib/themes/bogster.toml
+++ b/contrib/themes/bogster.toml
@@ -30,6 +30,7 @@
"ui.background" = { bg = "#161c23" }
"ui.linenr" = { fg = "#415367" }
+"ui.linenr.selected" = { fg = "#e5ded6" } # TODO
"ui.statusline" = { bg = "#232d38" }
"ui.popup" = { bg = "#232d38" }
"ui.window" = { bg = "#232d38" }
diff --git a/contrib/themes/ingrid.toml b/contrib/themes/ingrid.toml
index 0dd53164..da333fb8 100644
--- a/contrib/themes/ingrid.toml
+++ b/contrib/themes/ingrid.toml
@@ -30,6 +30,7 @@
"ui.background" = { bg = "#FFFCFD" }
"ui.linenr" = { fg = "#bbbbbb" }
+"ui.linenr.selected" = { fg = "#F3EAE9" } # TODO
"ui.statusline" = { bg = "#F3EAE9" }
"ui.popup" = { bg = "#F3EAE9" }
"ui.window" = { bg = "#D8B8B3" }
diff --git a/contrib/themes/onedark.toml b/contrib/themes/onedark.toml
index ccf6a2cc..4c13a217 100644
--- a/contrib/themes/onedark.toml
+++ b/contrib/themes/onedark.toml
@@ -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" }
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 95587b4c..63b3e277 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -232,7 +232,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 = {
@@ -329,6 +367,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;
@@ -357,40 +402,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(
diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs
index efb6a1af..51a21421 100644
--- a/helix-view/src/theme.rs
+++ b/helix-view/src/theme.rs
@@ -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
diff --git a/theme.toml b/theme.toml
index fd5572a6..903a5e26 100644
--- a/theme.toml
+++ b/theme.toml
@@ -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