diff --git a/book/src/editor.md b/book/src/editor.md index 8f3e2845..5e99ad2c 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -364,12 +364,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 | `"│"` | -| `skip-levels` | Number of indent levels to skip | `0` | -| `rainbow-indent` | Enum to set rainbow indentations. `normal`, `dim`, `none` | `none` | +| Key | Description | Default | +| --- | --- | --- | +| `render` | Whether to render indent guides | `false` | +| `character` | Literal character to use for rendering the indent guide | `"│"` | +| `skip-levels` | Number of indent levels to skip | `0` | +| `rainbow` | Whether to render indent guides in rainbow colors | `false` | Example: @@ -378,7 +378,7 @@ Example: render = true character = "╎" # Some characters that work well: "▏", "┆", "┊", "⸽" skip-levels = 1 -rainbow-indent = "normal" +rainbow = true ``` ### `[editor.gutters]` Section diff --git a/book/src/themes.md b/book/src/themes.md index 0edcbf05..2f91c8bb 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -149,7 +149,7 @@ berry = "#2A2A4D" ### Rainbow -The `rainbow` key is used for rainbow highlight for matching brackets and indentation. +The `rainbow` key is used for rainbow highlighting for matching brackets and indentation guides. The key is a list of styles. ```toml @@ -158,6 +158,20 @@ rainbow = ["#ff0000", "#ffa500", "#fff000", { fg = "#00ff00", modifiers = ["bold Colors from the palette and modifiers may be used. +The `rainbow-brackets` and `rainbow-indents` keys are used for rainbow highlights for matching brackets and indentation guides, respectively. +They inherit their default value from the `rainbow` key, but may be specified to provide different highlighting patterns for brackets and indentation. +For example, it may be desirable for indentation markers to be dimmer than brackets. (This is the default, when these are left unspecified.) + +```toml +rainbow-brackets = ["#ff0000", "#ffa500", "#fff000", "#00ff00"] +rainbow-indents = [ + { fg = "#ff0000", modifiers = ["dim"] }, + { fg = "#ffa500", modifiers = ["dim"] }, + { fg = "#fff000", modifiers = ["dim"] }, + { fg = "#00ff00", modifiers = ["dim"] } +] +``` + ### Scopes The following is a list of scopes available to use for styling: diff --git a/helix-term/src/ui/document.rs b/helix-term/src/ui/document.rs index 2aa13953..21717606 100644 --- a/helix-term/src/ui/document.rs +++ b/helix-term/src/ui/document.rs @@ -7,9 +7,9 @@ use helix_core::syntax::{self, HighlightEvent, Highlighter, OverlayHighlights}; use helix_core::text_annotations::TextAnnotations; use helix_core::{visual_offset_from_block, Position, RopeSlice}; use helix_stdx::rope::RopeSliceExt; -use helix_view::editor::{RainbowIndent, WhitespaceConfig, WhitespaceRenderValue}; +use helix_view::editor::{WhitespaceConfig, WhitespaceRenderValue}; use helix_view::graphics::Rect; -use helix_view::theme::{Modifier, Style}; +use helix_view::theme::Style; use helix_view::view::ViewPosition; use helix_view::{Document, Theme}; use tui::buffer::Buffer as Surface; @@ -179,7 +179,7 @@ pub struct TextRenderer<'a> { pub whitespace_style: Style, pub indent_guide_char: String, pub indent_guide_style: Style, - pub indent_guide_rainbow: RainbowIndent, + pub indent_guide_rainbow: bool, pub theme: &'a Theme, pub newline: String, pub nbsp: String, @@ -245,7 +245,7 @@ impl<'a> TextRenderer<'a> { }; let text_style = theme.get("ui.text"); - let basic_style = text_style.patch( + let indent_guide_style = text_style.patch( theme .try_get("ui.virtual.indent-guide") .unwrap_or_else(|| theme.get("ui.virtual.whitespace")), @@ -256,7 +256,7 @@ impl<'a> TextRenderer<'a> { TextRenderer { surface, indent_guide_char: editor_config.indent_guides.character.into(), - indent_guide_rainbow: editor_config.indent_guides.rainbow_indent.clone(), + indent_guide_rainbow: editor_config.indent_guides.rainbow, theme, newline, nbsp, @@ -269,7 +269,7 @@ impl<'a> TextRenderer<'a> { starting_indent: offset.col / indent_width as usize + !offset.col.is_multiple_of(indent_width as usize) as usize + editor_config.indent_guides.skip_levels as usize, - indent_guide_style: basic_style, + indent_guide_style, text_style, draw_indent_guides: editor_config.indent_guides.render, viewport, @@ -422,16 +422,14 @@ impl<'a> TextRenderer<'a> { as u16; let y = self.viewport.y + row; debug_assert!(self.surface.in_bounds(x, y)); - let style = match self.indent_guide_rainbow { - RainbowIndent::None => self.indent_guide_style, - RainbowIndent::Dim => self - .indent_guide_style - .patch(self.theme.get_rainbow(i)) - .add_modifier(Modifier::DIM), - RainbowIndent::Normal => self.indent_guide_style.patch(self.theme.get_rainbow(i)), + let indent_guide_style = if self.indent_guide_rainbow { + self.indent_guide_style + .patch(self.theme.get_indent_rainbow(i)) + } else { + self.indent_guide_style }; self.surface - .set_string(x, y, &self.indent_guide_char, style) + .set_string(x, y, &self.indent_guide_char, indent_guide_style) } } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 3bd66f94..3be57e9e 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -343,7 +343,7 @@ impl EditorView { .map_or(visible_range.start as u32, |node| node.start_byte()); let range = start..visible_range.end as u32; - Some(syntax.rainbow_highlights(text, theme.rainbow_length(), loader, range)) + Some(syntax.rainbow_highlights(text, theme.rainbow_bracket_length(), loader, range)) } /// Get highlight spans for document diagnostics diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 38c67137..8e7277ca 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1089,21 +1089,13 @@ impl Default for WhitespaceCharacters { } } -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "kebab-case")] -pub enum RainbowIndent { - 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, pub skip_levels: u8, - pub rainbow_indent: RainbowIndent, + pub rainbow: bool, } impl Default for IndentGuidesConfig { @@ -1112,7 +1104,7 @@ impl Default for IndentGuidesConfig { skip_levels: 0, render: false, character: '│', - rainbow_indent: RainbowIndent::None, + rainbow: false, } } } diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 6ed71dcd..0fbc369d 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -280,7 +280,8 @@ pub struct Theme { /// Reverse map from scope string to its `Highlight` index. `find_highlight_exact` /// is called many times per frame, so we optimize lookups. scope_index: HashMap, - rainbow_length: usize, + rainbow_bracket_length: usize, + rainbow_indent_length: usize, } impl From for Theme { @@ -315,12 +316,14 @@ fn build_theme_values( Vec, Vec