From a27c384dd23bfe97734944843bff2862214bd78e Mon Sep 17 00:00:00 2001 From: s0LA1337 Date: Sat, 1 Oct 2022 00:44:35 +0000 Subject: [PATCH] Initial implementation of colored indentation guides --- book/src/configuration.md | 10 ++++++---- helix-term/src/ui/editor.rs | 20 +++++++++++++++++--- helix-view/src/editor.rs | 2 ++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index fdabe768..3a5ab4a2 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -218,10 +218,11 @@ tabpad = "·" # Tabs will look like "→···" (depending on tab width) Options for rendering vertical indent guides. -| Key | Description | Default | -| --- | --- | --- | -| `render` | Whether to render indent guides. | `false` | -| `character` | Literal character to use for rendering the indent guide | `│` | +| Key | Description | Default | +| --- | --- | --- | +| `render` | Whether to render indent guides. | `false` | +| `character` | Literal character to use for rendering the indent guide | `│` | +| `rainbow` | Whether or not the indent guides shall have changing colors. | `false` | Example: @@ -229,4 +230,5 @@ Example: [editor.indent-guides] render = true character = "╎" +rainbow = true ``` diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 7cb29c3b..69e565e1 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -421,17 +421,26 @@ impl EditorView { let text_style = theme.get("ui.text"); let whitespace_style = theme.get("ui.virtual.whitespace"); + let indent_rainbow_colors = [ + helix_view::graphics::Color::Red, + helix_view::graphics::Color::Yellow, + helix_view::graphics::Color::Green, + helix_view::graphics::Color::Cyan, + helix_view::graphics::Color::Blue, + helix_view::graphics::Color::Magenta, + ]; + let mut is_in_indent_area = true; - let mut last_line_indent_level = 0; + let mut last_line_indent_level: u16 = 0; // use whitespace style as fallback for indent-guide - let indent_guide_style = text_style.patch( + let mut indent_guide_style = text_style.patch( theme .try_get("ui.virtual.indent-guide") .unwrap_or_else(|| theme.get("ui.virtual.whitespace")), ); - let draw_indent_guides = |indent_level, line, surface: &mut Surface| { + let mut draw_indent_guides = |indent_level, line, surface: &mut Surface| { if !config.indent_guides.render { return; } @@ -441,6 +450,11 @@ impl EditorView { // extra loops if the code is deeply nested. for i in starting_indent..(indent_level / tab_width as u16) { + if config.indent_guides.rainbow { + let color_index: usize = i as usize % indent_rainbow_colors.len(); + indent_guide_style.fg = Some(indent_rainbow_colors[color_index]); + } + surface.set_string( viewport.x + (i * tab_width as u16) - offset.col as u16, viewport.y + line, diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 5eff9983..5acbc5b7 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -533,6 +533,7 @@ impl Default for WhitespaceCharacters { pub struct IndentGuidesConfig { pub render: bool, pub character: char, + pub rainbow: bool, } impl Default for IndentGuidesConfig { @@ -540,6 +541,7 @@ impl Default for IndentGuidesConfig { Self { render: false, character: '│', + rainbow: false, } } }