on master help sign in
Add mode specific styles (#2676)

* Add mode specific styles In similar vein to neovim's lualine and similar statusline packages this allows helix users to style their mode based on which mode it is thus making each mode more visually distinct at a glance * Add an example based on rosepine * Add editor.colors-mode config * Document statusline mode styles

commitd06800f1dd47315f5738c529d40d1e0952ee2115 authorMathspy <mathspy257@gmail.com> dateThu 30 Jun 2022, 05:26 (4 years ago) parented89f88
5 files changed+26−9
book/src/configuration.md+1 book/src/themes.md+5−2 helix-term/src/ui/editor.rs+14−7 helix-view/src/editor.rs+3 runtime/themes/rose_pine.toml+3
book/src/configuration.md+1
@@ -46,6 +46,7 @@ hidden = false
4646| `auto-info` | Whether to display infoboxes | `true` |
4747| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` |
4848| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` |
49+| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
4950
5051### `[editor.lsp]` Section
5152
book/src/themes.md+5−2
@@ -219,6 +219,9 @@ These scopes are used for theming the editor interface.
219219| `ui.linenr.selected` | Line number for the line the cursor is on |
220220| `ui.statusline` | Statusline |
221221| `ui.statusline.inactive` | Statusline (unfocused document) |
222+| `ui.statusline.normal` | Statusline mode during normal mode ([only if `editor.color-modes` is enabled][editor-section]) |
223+| `ui.statusline.insert` | Statusline mode during insert mode ([only if `editor.color-modes` is enabled][editor-section]) |
224+| `ui.statusline.select` | Statusline mode during select mode ([only if `editor.color-modes` is enabled][editor-section]) |
222225| `ui.popup` | Documentation popups (e.g space-k) |
223226| `ui.popup.info` | Prompt for multiple key options |
224227| `ui.window` | Border lines separating splits |
@@ -226,7 +229,7 @@ These scopes are used for theming the editor interface.
226229| `ui.text` | Command prompts, popup text, etc. |
227230| `ui.text.focus` | |
228231| `ui.text.info` | The key: command text in `ui.popup.info` boxes |
229−| `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][rulers-config])|
232+| `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][editor-section])|
230233| `ui.virtual.whitespace` | Visible white-space characters |
231234| `ui.virtual.indent-guide` | Vertical indent width guides |
232235| `ui.menu` | Code and command completion menus |
@@ -246,4 +249,4 @@ These scopes are used for theming the editor interface.
246249| `diagnostic.warning` | Diagnostics warning (editing area) |
247250| `diagnostic.error` | Diagnostics error (editing area) |
248251
249−[rulers-config]: ./configuration.md#editor-section
252+[editor-section]: ./configuration.md#editor-section
helix-term/src/ui/editor.rs+14−7
@@ -161,7 +161,7 @@ impl EditorView {
161161 .area
162162 .clip_top(view.area.height.saturating_sub(1))
163163 .clip_bottom(1); // -1 from bottom to remove commandline
164− self.render_statusline(doc, view, statusline_area, surface, theme, is_focused);
164+ self.render_statusline(editor, doc, view, statusline_area, surface, is_focused);
165165 }
166166
167167 pub fn render_rulers(
@@ -732,11 +732,11 @@ impl EditorView {
732732
733733 pub fn render_statusline(
734734 &self,
735+ editor: &Editor,
735736 doc: &Document,
736737 view: &View,
737738 viewport: Rect,
738739 surface: &mut Surface,
739− theme: &Theme,
740740 is_focused: bool,
741741 ) {
742742 use tui::text::{Span, Spans};
@@ -745,10 +745,11 @@ impl EditorView {
745745 // Left side of the status line.
746746 //-------------------------------
747747
748− let mode = match doc.mode() {
749− Mode::Insert => "INS",
750− Mode::Select => "SEL",
751− Mode::Normal => "NOR",
748+ let theme = &editor.theme;
749+ let (mode, mode_style) = match doc.mode() {
750+ Mode::Insert => (" INS ", theme.get("ui.statusline.insert")),
751+ Mode::Select => (" SEL ", theme.get("ui.statusline.select")),
752+ Mode::Normal => (" NOR ", theme.get("ui.statusline.normal")),
752753 };
753754 let progress = doc
754755 .language_server()
@@ -767,7 +768,13 @@ impl EditorView {
767768 // statusline
768769 surface.set_style(viewport.with_height(1), base_style);
769770 if is_focused {
770− surface.set_string(viewport.x + 1, viewport.y, mode, base_style);
771+ let color_modes = editor.config().color_modes;
772+ surface.set_string(
773+ viewport.x,
774+ viewport.y,
775+ mode,
776+ if color_modes { mode_style } else { base_style },
777+ );
771778 }
772779 surface.set_string(viewport.x + 5, viewport.y, progress, base_style);
773780
helix-view/src/editor.rs+3
@@ -161,6 +161,8 @@ pub struct Config {
161161 pub whitespace: WhitespaceConfig,
162162 /// Vertical indent width guides.
163163 pub indent_guides: IndentGuidesConfig,
164+ /// Whether to color modes with different colors. Defaults to `false`.
165+ pub color_modes: bool,
164166}
165167
166168#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
@@ -414,6 +416,7 @@ impl Default for Config {
414416 rulers: Vec::new(),
415417 whitespace: WhitespaceConfig::default(),
416418 indent_guides: IndentGuidesConfig::default(),
419+ color_modes: false,
417420 }
418421 }
419422}
runtime/themes/rose_pine.toml+3
@@ -9,6 +9,9 @@
99"ui.selection" = { bg = "highlight" }
1010"comment" = "subtle"
1111"ui.statusline" = {fg = "foam", bg = "surface" }
12+"ui.statusline.insert" = {fg = "base", bg = "foam", modifiers = ["bold"]}
13+"ui.statusline.normal" = {fg = "base", bg = "rose", modifiers = ["bold"]}
14+"ui.statusline.select" = {fg = "base", bg = "iris", modifiers = ["bold"]}
1215"ui.statusline.inactive" = { fg = "iris", bg = "surface" }
1316"ui.cursor" = { fg = "rose", modifiers = ["reversed"] }
1417"ui.text" = { fg = "text" }