Skip to content

Commit d1517c6

Browse files
committed
Update to new TextRenderer
Docs fmt
1 parent 7f47756 commit d1517c6

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

book/src/configuration.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,12 @@ tabpad = "·" # Tabs will look like "→···" (depending on tab width)
245245

246246
Options for rendering vertical indent guides.
247247

248-
| Key | Description | Default |
249-
| --- | --- | --- |
250-
| `render` | Whether to render indent guides. | `false` |
251-
| `character` | Literal character to use for rendering the indent guide | `` |
252-
| `skip-levels` | Number of indent levels to skip | `0` |
248+
| Key | Description | Default |
249+
| --- | --- | --- |
250+
| `render` | Whether to render indent guides. | `false` |
251+
| `character` | Literal character to use for rendering the indent guide | `` |
252+
| `skip-levels` | Number of indent levels to skip | `0` |
253+
| `rainbow-option` | Enum to set rainbow indentations. Options: `normal`, `dim` and `none`| `none` |
253254

254255
Example:
255256

@@ -258,6 +259,7 @@ Example:
258259
render = true
259260
character = "" # Some characters that work well: "▏", "┆", "┊", "⸽"
260261
skip-levels = 1
262+
rainbow-option = "normal"
261263
```
262264

263265
### `[editor.gutters]` Section

helix-term/src/ui/document.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use helix_core::syntax::Highlight;
77
use helix_core::syntax::HighlightEvent;
88
use helix_core::text_annotations::TextAnnotations;
99
use helix_core::{visual_offset_from_block, Position, RopeSlice};
10-
use helix_view::editor::{WhitespaceConfig, WhitespaceRenderValue};
10+
use helix_view::editor::{RainbowIndentOptions, WhitespaceConfig, WhitespaceRenderValue};
1111
use helix_view::graphics::Rect;
12-
use helix_view::theme::Style;
12+
use helix_view::theme::{Modifier, Style};
1313
use helix_view::view::ViewPosition;
1414
use helix_view::Document;
1515
use helix_view::Theme;
@@ -318,6 +318,8 @@ pub struct TextRenderer<'a> {
318318
pub whitespace_style: Style,
319319
pub indent_guide_char: String,
320320
pub indent_guide_style: Style,
321+
pub indent_guide_rainbow: RainbowIndentOptions,
322+
pub theme: &'a Theme,
321323
pub newline: String,
322324
pub nbsp: String,
323325
pub space: String,
@@ -333,7 +335,7 @@ impl<'a> TextRenderer<'a> {
333335
pub fn new(
334336
surface: &'a mut Surface,
335337
doc: &Document,
336-
theme: &Theme,
338+
theme: &'a Theme,
337339
col_offset: usize,
338340
viewport: Rect,
339341
) -> TextRenderer<'a> {
@@ -369,10 +371,17 @@ impl<'a> TextRenderer<'a> {
369371
};
370372

371373
let text_style = theme.get("ui.text");
374+
let basic_style = text_style.patch(
375+
theme
376+
.try_get("ui.virtual.indent-guide")
377+
.unwrap_or_else(|| theme.get("ui.virtual.whitespace")),
378+
);
372379

373380
TextRenderer {
374381
surface,
375382
indent_guide_char: editor_config.indent_guides.character.into(),
383+
indent_guide_rainbow: editor_config.indent_guides.rainbow_option.clone(),
384+
theme,
376385
newline,
377386
nbsp,
378387
space,
@@ -381,11 +390,7 @@ impl<'a> TextRenderer<'a> {
381390
whitespace_style: theme.get("ui.virtual.whitespace"),
382391
starting_indent: (col_offset / tab_width)
383392
+ editor_config.indent_guides.skip_levels as usize,
384-
indent_guide_style: text_style.patch(
385-
theme
386-
.try_get("ui.virtual.indent-guide")
387-
.unwrap_or_else(|| theme.get("ui.virtual.whitespace")),
388-
),
393+
indent_guide_style: basic_style,
389394
text_style,
390395
draw_indent_guides: editor_config.indent_guides.render,
391396
viewport,
@@ -471,8 +476,25 @@ impl<'a> TextRenderer<'a> {
471476
(self.viewport.x as usize + (i * self.tab_width as usize) - self.col_offset) as u16;
472477
let y = self.viewport.y + row;
473478
debug_assert!(self.surface.in_bounds(x, y));
474-
self.surface
475-
.set_string(x, y, &self.indent_guide_char, self.indent_guide_style);
479+
match self.indent_guide_rainbow {
480+
RainbowIndentOptions::None => {
481+
self.surface
482+
.set_string(x, y, &self.indent_guide_char, self.indent_guide_style)
483+
}
484+
RainbowIndentOptions::Dim => {
485+
let new_style = self
486+
.indent_guide_style
487+
.patch(self.theme.get_rainbow(i))
488+
.add_modifier(Modifier::DIM);
489+
self.surface
490+
.set_string(x, y, &self.indent_guide_char, new_style);
491+
}
492+
RainbowIndentOptions::Normal => {
493+
let new_style = self.indent_guide_style.patch(self.theme.get_rainbow(i));
494+
self.surface
495+
.set_string(x, y, &self.indent_guide_char, new_style);
496+
}
497+
};
476498
}
477499
}
478500
}

helix-view/src/editor.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,21 @@ impl Default for WhitespaceCharacters {
718718
}
719719
}
720720

721+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
722+
#[serde(rename_all = "kebab-case")]
723+
pub enum RainbowIndentOptions {
724+
None,
725+
Dim,
726+
Normal,
727+
}
728+
721729
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
722730
#[serde(default, rename_all = "kebab-case")]
723731
pub struct IndentGuidesConfig {
724732
pub render: bool,
725733
pub character: char,
726734
pub skip_levels: u8,
735+
pub rainbow_option: RainbowIndentOptions,
727736
}
728737

729738
impl Default for IndentGuidesConfig {
@@ -732,6 +741,7 @@ impl Default for IndentGuidesConfig {
732741
skip_levels: 0,
733742
render: false,
734743
character: '│',
744+
rainbow_option: RainbowIndentOptions::None,
735745
}
736746
}
737747
}

helix-view/src/theme.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ impl Theme {
367367
pub fn rainbow_length(&self) -> usize {
368368
self.rainbow_length
369369
}
370+
371+
pub fn get_rainbow(&self, index: usize) -> Style {
372+
self.highlights[index % self.rainbow_length]
373+
}
370374
}
371375

372376
fn default_rainbow() -> Vec<Style> {

0 commit comments

Comments
 (0)