Merge branch 'colored-indent-guides'

pull/6/head
trivernis 2 years ago
commit 25e095adf1
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -254,12 +254,40 @@ Sets explorer side width and style.
Options for rendering vertical indent guides.
<<<<<<< HEAD
| Key | Description | Default |
| --- | --- | --- |
| `render` | Whether to render indent guides. | `true` |
| `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` |
||||||| merged common ancestors
<<<<<<<<< Temporary merge branch 1
| 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` |
||||||||| 60aa7d36
| 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 | `│` |
| `skip-levels` | Number of indent levels to skip | `0` |
>>>>>>>>> Temporary merge branch 2
=======
| 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` |
>>>>>>> colored-indent-guides
Example:
@ -267,7 +295,18 @@ Example:
[editor.indent-guides]
render = true
character = "╎"
<<<<<<< HEAD
rainbow = true
||||||| merged common ancestors
rainbow = true
||||||||| 60aa7d36
character = "╎"
=========
character = "╎" # Some characters that work well: "▏", "┆", "┊", "⸽"
=======
rainbow = "normal"
character = "╎" # Some characters that work well: "▏", "┆", "┊", "⸽"
>>>>>>> colored-indent-guides
skip-levels = 1
```

@ -107,6 +107,7 @@ Some styles might not be supported by your terminal emulator.
| `double_line` |
<<<<<<< HEAD
<<<<<<< HEAD
### Rainbow
@ -121,6 +122,20 @@ Colors from the palette and modifiers may be used.
||||||| 60aa7d36
=======
||||||| merged common ancestors
=======
### Rainbow
The `rainbow` key is used for rainbow highlight for matching brackets.
The key is a list of styles.
```toml
rainbow = ["#ff0000", "#ffa500", "#fff000", { fg = "#00ff00", modifiers = ["bold"] }]
```
Colors from the palette and modifiers may be used.
>>>>>>> colored-indent-guides
### Inheritance
Extend upon other themes by setting the `inherits` property to an existing theme.
@ -136,7 +151,22 @@ inherits = "boo_berry"
berry = "#2A2A4D"
```
<<<<<<< HEAD
>>>>>>> seperate_code_action
||||||| merged common ancestors
### Rainbow
The `rainbow` key is used for rainbow highlight for matching brackets.
The key is a list of styles.
```toml
rainbow = ["#ff0000", "#ffa500", "#fff000", { fg = "#00ff00", modifiers = ["bold"] }]
```
Colors from the palette and modifiers may be used.
=======
>>>>>>> colored-indent-guides
### Scopes
The following is a list of scopes available to use for styling.

@ -19,7 +19,7 @@ use helix_core::{
use helix_view::{
apply_transaction,
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},
@ -471,15 +471,22 @@ impl EditorView {
let starting_indent =
(offset.col / tab_width) + config.indent_guides.skip_levels as usize;
let modifier = if config.indent_guides.rainbow == RainbowIndentOptions::Dim {
Modifier::DIM
} else {
Modifier::empty()
};
for i in starting_indent..(indent_level / tab_width) {
let style = if config.indent_guides.rainbow {
let color_index = i as usize % theme.rainbow_length();
indent_guide_style.patch(theme.get(&format!("rainbow.{}", color_index)))
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
};
surface.set_string(
viewport.x + ((i * tab_width) - offset.col) as u16,
viewport.x + (i as u16 * tab_width as u16) - offset.col as u16,
viewport.y + line,
&indent_guide_char,
style,

@ -620,12 +620,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,
pub rainbow: bool,
pub rainbow: RainbowIndentOptions,
pub skip_levels: u8,
}
@ -635,7 +643,7 @@ impl Default for IndentGuidesConfig {
render: true,
skip_levels: 0,
character: '',
rainbow: false,
rainbow: RainbowIndentOptions::None,
}
}
}

@ -188,8 +188,8 @@ pub struct Theme {
styles: HashMap<String, Style>,
// tree-sitter highlight styles are stored in a Vec to optimize lookups
scopes: Vec<String>,
highlights: Vec<Style>,
rainbow_length: usize,
highlights: Vec<Style>,
}
impl From<Value> for Theme {
@ -197,17 +197,13 @@ impl From<Value> for Theme {
let values: Result<HashMap<String, Value>> =
toml::from_str(&value.to_string()).context("Failed to load theme");
let (styles, scopes, highlights) = build_theme_values(values);
let rainbow_length = styles
.iter()
.filter(|s| s.0.starts_with("rainbow."))
.count();
let (styles, scopes, rainbow_length, highlights) = build_theme_values(values);
Self {
styles,
scopes,
highlights,
rainbow_length,
highlights,
..Default::default()
}
}
@ -275,8 +271,8 @@ impl<'de> Deserialize<'de> for Theme {
Ok(Self {
styles,
scopes,
highlights,
rainbow_length,
highlights,
..Default::default()
})
}
@ -284,10 +280,11 @@ impl<'de> Deserialize<'de> for Theme {
fn build_theme_values(
values: Result<HashMap<String, Value>>,
) -> (HashMap<String, Style>, Vec<String>, Vec<Style>) {
) -> (HashMap<String, Style>, Vec<String>, usize, Vec<Style>) {
let mut styles = HashMap::new();
let mut scopes = Vec::new();
let mut highlights = Vec::new();
let mut rainbow_length = 0;
if let Ok(mut colors) = values {
// TODO: alert user of parsing failures in editor
@ -305,6 +302,27 @@ fn build_theme_values(
styles.reserve(colors.len());
scopes.reserve(colors.len());
highlights.reserve(colors.len());
for (i, style) in colors
.remove("rainbow")
.and_then(|value| match palette.parse_style_array(value) {
Ok(styles) => Some(styles),
Err(err) => {
warn!("{}", err);
None
}
})
.unwrap_or_else(Theme::default_rainbow)
.iter()
.enumerate()
{
let name = format!("rainbow.{}", i);
styles.insert(name.clone(), *style);
scopes.push(name);
highlights.push(*style);
rainbow_length += 1;
}
for (name, style_value) in colors {
let mut style = Style::default();
if let Err(err) = palette.parse_style(&mut style, style_value) {
@ -318,7 +336,7 @@ fn build_theme_values(
}
}
(styles, scopes, highlights)
(styles, scopes, rainbow_length, highlights)
}
impl Theme {
#[inline]
@ -374,6 +392,10 @@ impl Theme {
}
}
pub fn get_rainbow(&self, index: usize) -> Style {
self.highlights[index % self.rainbow_length]
}
pub fn default_rainbow() -> Vec<Style> {
vec![
Style::default().fg(Color::Red),

Loading…
Cancel
Save