Initial implementation of colored indentation guides

pull/6/head
s0LA1337 2 years ago
parent 60aa7d3607
commit a27c384dd2

@ -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
```

@ -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,

@ -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,
}
}
}

Loading…
Cancel
Save