From 52db599f2bd169d0c23902d970eba87c34238bf3 Mon Sep 17 00:00:00 2001 From: SoraTenshi Date: Sun, 23 Oct 2022 18:52:22 +0000 Subject: [PATCH] Add style for rainbow ig, dimming, normal and none --- book/src/configuration.md | 14 +++++++------- helix-term/src/ui/editor.rs | 14 +++++++++++--- helix-view/src/editor.rs | 13 ++++++++++--- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index 63279403..3fd1bd17 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -237,12 +237,12 @@ 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 | `│` | -| `rainbow` | Whether or not the indent guides shall have changing colors. | `false` | -| `skip-levels` | Number of indent levels to skip | `0` | +| 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. It can be `none`, `dim` or `normal`| `none` | +| `skip-levels` | Number of indent levels to skip | `0` | Example: @@ -250,6 +250,6 @@ Example: [editor.indent-guides] render = true character = "╎" -rainbow = true +rainbow = "normal" skip-levels = 1 ``` diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 1826d173..ebc00c5b 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -17,7 +17,7 @@ use helix_core::{ }; use helix_view::{ document::{Mode, SCRATCH_BUFFER_NAME}, - editor::{CompleteAction, CursorShapeConfig}, + editor::{CompleteAction, CursorShapeConfig, RainbowIndentOptions}, graphics::{Color, CursorKind, Modifier, Rect, Style}, input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind}, keyboard::{KeyCode, KeyModifiers}, @@ -443,9 +443,17 @@ impl EditorView { // TODO: limit to a max indent level too. It doesn't cause visual artifacts but it would avoid some // extra loops if the code is deeply nested. + let modifier = if config.indent_guides.rainbow == RainbowIndentOptions::Dim { + Modifier::DIM + } else { + Modifier::empty() + }; + for i in starting_indent..(indent_level / tab_width as u16) { - let style = if config.indent_guides.rainbow { - indent_guide_style.patch(theme.get_rainbow(i as usize)) + let style = if config.indent_guides.rainbow != RainbowIndentOptions::None { + indent_guide_style + .patch(theme.get_rainbow(i as usize)) + .add_modifier(modifier) } else { indent_guide_style }; diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index bdf2be88..cbaa7d10 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -551,13 +551,20 @@ impl Default for WhitespaceCharacters { } } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum RainbowIndentOptions { + None, + Dim, + Normal, +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] pub struct IndentGuidesConfig { pub render: bool, pub character: char, - // TODO: Make enum to also support background rainbow for indent guides - pub rainbow: bool, + pub rainbow: RainbowIndentOptions, pub skip_levels: u16, } @@ -567,7 +574,7 @@ impl Default for IndentGuidesConfig { skip_levels: 0, render: false, character: '│', - rainbow: false, + rainbow: RainbowIndentOptions::None, } } }