on master help sign in
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

commitd1c8a74771b241ee0824853bd5e8229cb0ab4187 authorGokul Soumya <gokulps15@gmail.com> dateMon 14 Jun 2021, 19:31 (5 years ago) parent33a35b7
7 files changed+56−38
book/src/configuration.md+1 contrib/themes/bogster.toml+1 contrib/themes/ingrid.toml+1 contrib/themes/onedark.toml+1 helix-term/src/ui/editor.rs+46−35 helix-view/src/theme.rs+5−3 theme.toml+1
book/src/configuration.md+1
@@ -70,6 +70,7 @@ Possible keys:
7070| `module` | |
7171| `ui.background` | |
7272| `ui.linenr` | |
73+| `ui.linenr.selected` | For lines with cursors |
7374| `ui.statusline` | |
7475| `ui.popup` | |
7576| `ui.window` | |
contrib/themes/bogster.toml+1
@@ -30,6 +30,7 @@
3030
3131"ui.background" = { bg = "#161c23" }
3232"ui.linenr" = { fg = "#415367" }
33+"ui.linenr.selected" = { fg = "#e5ded6" } # TODO
3334"ui.statusline" = { bg = "#232d38" }
3435"ui.popup" = { bg = "#232d38" }
3536"ui.window" = { bg = "#232d38" }
contrib/themes/ingrid.toml+1
@@ -30,6 +30,7 @@
3030
3131"ui.background" = { bg = "#FFFCFD" }
3232"ui.linenr" = { fg = "#bbbbbb" }
33+"ui.linenr.selected" = { fg = "#F3EAE9" } # TODO
3334"ui.statusline" = { bg = "#F3EAE9" }
3435"ui.popup" = { bg = "#F3EAE9" }
3536"ui.window" = { bg = "#D8B8B3" }
contrib/themes/onedark.toml+1
@@ -33,6 +33,7 @@
3333"ui.background" = { fg = "#ABB2BF", bg = "#282C34" }
3434"ui.help" = { bg = "#3E4452" }
3535"ui.linenr" = { fg = "#4B5263", modifiers = ['dim'] }
36+"ui.linenr.selected" = { fg = "#ABB2BF" }
3637"ui.popup" = { bg = "#3E4452" }
3738"ui.statusline" = { fg = "#ABB2BF", bg = "#2C323C" }
3839"ui.selection" = { bg = "#3E4452" }
helix-term/src/ui/editor.rs+46−35
@@ -232,7 +232,45 @@ impl EditorView {
232232 }
233233 }
234234
235− // render selections
235+ // render gutters
236+
237+ let linenr: Style = theme.get("ui.linenr");
238+ let warning: Style = theme.get("warning");
239+ let error: Style = theme.get("error");
240+ let info: Style = theme.get("info");
241+ let hint: Style = theme.get("hint");
242+
243+ for (i, line) in (view.first_line..last_line).enumerate() {
244+ use helix_core::diagnostic::Severity;
245+ if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
246+ surface.set_stringn(
247+ viewport.x - OFFSET,
248+ viewport.y + i as u16,
249+ "●",
250+ 1,
251+ match diagnostic.severity {
252+ Some(Severity::Error) => error,
253+ Some(Severity::Warning) | None => warning,
254+ Some(Severity::Info) => info,
255+ Some(Severity::Hint) => hint,
256+ },
257+ );
258+ }
259+
260+ // line numbers having selections are rendered differently
261+ surface.set_stringn(
262+ viewport.x + 1 - OFFSET,
263+ viewport.y + i as u16,
264+ format!("{:>5}", line + 1),
265+ 5,
266+ linenr,
267+ );
268+ }
269+
270+ // render selections and selected linenr(s)
271+ let linenr_select: Style = theme
272+ .try_get("ui.linenr.selected")
273+ .unwrap_or_else(|| theme.get("ui.linenr"));
236274
237275 if is_focused {
238276 let screen = {
@@ -329,6 +367,13 @@ impl EditorView {
329367 ),
330368 cursor_style,
331369 );
370+ surface.set_stringn(
371+ viewport.x + 1 - OFFSET,
372+ viewport.y + head.row as u16,
373+ format!("{:>5}", view.first_line + head.row + 1),
374+ 5,
375+ linenr_select,
376+ );
332377 // TODO: set cursor position for IME
333378 if let Some(syntax) = doc.syntax() {
334379 use helix_core::match_brackets;
@@ -357,40 +402,6 @@ impl EditorView {
357402 }
358403 }
359404 }
360−
361− // render gutters
362−
363− let style: Style = theme.get("ui.linenr");
364− let warning: Style = theme.get("warning");
365− let error: Style = theme.get("error");
366− let info: Style = theme.get("info");
367− let hint: Style = theme.get("hint");
368−
369− for (i, line) in (view.first_line..last_line).enumerate() {
370− use helix_core::diagnostic::Severity;
371− if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
372− surface.set_stringn(
373− viewport.x - OFFSET,
374− viewport.y + i as u16,
375− "●",
376− 1,
377− match diagnostic.severity {
378− Some(Severity::Error) => error,
379− Some(Severity::Warning) | None => warning,
380− Some(Severity::Info) => info,
381− Some(Severity::Hint) => hint,
382− },
383− );
384− }
385−
386− surface.set_stringn(
387− viewport.x + 1 - OFFSET,
388− viewport.y + i as u16,
389− format!("{:>5}", line + 1),
390− 5,
391− style,
392− );
393− }
394405 }
395406
396407 pub fn render_diagnostics(
helix-view/src/theme.rs+5−3
@@ -200,12 +200,14 @@ fn parse_modifier(value: &Value) -> Option<Modifier> {
200200
201201impl Theme {
202202 pub fn get(&self, scope: &str) -> Style {
203− self.styles
204− .get(scope)
205− .copied()
203+ self.try_get(scope)
206204 .unwrap_or_else(|| Style::default().fg(Color::Rgb(0, 0, 255)))
207205 }
208206
207+ pub fn try_get(&self, scope: &str) -> Option<Style> {
208+ self.styles.get(scope).copied()
209+ }
210+
209211 #[inline]
210212 pub fn scopes(&self) -> &[String] {
211213 &self.scopes
theme.toml+1
@@ -40,6 +40,7 @@
4040
4141"ui.background" = { bg = "#3b224c" } # midnight
4242"ui.linenr" = { fg = "#5a5977" } # comet
43+"ui.linenr.selected" = { fg = "#dbbfef" } # lilac
4344"ui.statusline" = { bg = "#281733" } # revolver
4445"ui.popup" = { bg = "#281733" } # revolver
4546"ui.window" = { bg = "#452859" } # bossa nova