Add `ruler-style` option in addition to `ruler-char`

pull/11798/head
Denis Gruzdev 2 months ago
parent 6ae04aacea
commit 4acdbe3699
No known key found for this signature in database
GPG Key ID: E3DFEC736900FDE2

@ -42,7 +42,8 @@
| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` |
| `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` | | `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` |
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` |
| `ruler-char` | Specifies the character used to display the rulers. When unset, the rulers will be indicated by a subtle background or style change, depending on the theme in use | `none` | | `ruler-style` | `bg` displays the ruler as a background color, while `char` displays the configured `ruler-char` | `bg` |
| `ruler-char` | Specifies the character used to display the rulers when `ruler-style` is `char` | `│` |
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | | `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | | `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
| `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` | | `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` |

@ -24,7 +24,7 @@ use helix_core::{
use helix_view::{ use helix_view::{
annotations::diagnostics::DiagnosticFilter, annotations::diagnostics::DiagnosticFilter,
document::{Mode, SavePoint, SCRATCH_BUFFER_NAME}, document::{Mode, SavePoint, SCRATCH_BUFFER_NAME},
editor::{CompleteAction, CursorShapeConfig}, editor::{CompleteAction, CursorShapeConfig, RulerStyle},
graphics::{Color, CursorKind, Modifier, Rect, Style}, graphics::{Color, CursorKind, Modifier, Rect, Style},
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind}, input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
keyboard::{KeyCode, KeyModifiers}, keyboard::{KeyCode, KeyModifiers},
@ -254,11 +254,12 @@ impl EditorView {
theme: &Theme, theme: &Theme,
) { ) {
let editor_rulers = &editor.config().rulers; let editor_rulers = &editor.config().rulers;
let editor_ruler_char = editor.config().ruler_char.map(|c| c.to_string()); let ruler_style = &editor.config().ruler_style;
let ruler_char = editor.config().ruler_char.to_string();
let theme_key = match &editor_ruler_char { let theme_key = match ruler_style {
None => "ui.virtual.ruler", RulerStyle::Bg => "ui.virtual.ruler",
Some(_) => "ui.virtual.ruler.char", RulerStyle::Char => "ui.virtual.ruler.char",
}; };
let ruler_theme = theme let ruler_theme = theme
@ -280,12 +281,15 @@ impl EditorView {
.filter(|ruler| ruler < &viewport.width) .filter(|ruler| ruler < &viewport.width)
.map(|ruler| viewport.clip_left(ruler).with_width(1)) .map(|ruler| viewport.clip_left(ruler).with_width(1))
.for_each(|area| { .for_each(|area| {
if let Some(ruler_char) = &editor_ruler_char { match ruler_style {
RulerStyle::Bg => {
surface.set_style(area, ruler_theme);
}
RulerStyle::Char => {
for y in area.y..area.height { for y in area.y..area.height {
surface.set_string(area.x, y, ruler_char, ruler_theme) surface.set_string(area.x, y, &ruler_char, ruler_theme);
}
} }
} else {
surface.set_style(area, ruler_theme)
} }
}) })
} }

@ -314,8 +314,10 @@ pub struct Config {
pub terminal: Option<TerminalConfig>, pub terminal: Option<TerminalConfig>,
/// Column numbers at which to draw the rulers. Defaults to `[]`, meaning no rulers. /// Column numbers at which to draw the rulers. Defaults to `[]`, meaning no rulers.
pub rulers: Vec<u16>, pub rulers: Vec<u16>,
/// Character used to draw the rulers when specified. If `None`, rulers are drawn using style only. /// Set to `bg` to display rulers with background color (default) or `char` to use character from `ruler-char`.
pub ruler_char: Option<char>, pub ruler_style: RulerStyle,
/// Character used to draw the rulers when specified
pub ruler_char: char,
#[serde(default)] #[serde(default)]
pub whitespace: WhitespaceConfig, pub whitespace: WhitespaceConfig,
/// Persistently display open buffers along the top /// Persistently display open buffers along the top
@ -638,6 +640,17 @@ impl Default for CursorShapeConfig {
} }
} }
/// ruler render style
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum RulerStyle {
/// Render rulers with background color
#[default]
Bg,
/// Render rulers with character from `ruler-char`
Char,
}
/// bufferline render modes /// bufferline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
@ -965,7 +978,8 @@ impl Default for Config {
lsp: LspConfig::default(), lsp: LspConfig::default(),
terminal: get_terminal_provider(), terminal: get_terminal_provider(),
rulers: Vec::new(), rulers: Vec::new(),
ruler_char: None, ruler_style: RulerStyle::default(),
ruler_char: '',
whitespace: WhitespaceConfig::default(), whitespace: WhitespaceConfig::default(),
bufferline: BufferLine::default(), bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(), indent_guides: IndentGuidesConfig::default(),

Loading…
Cancel
Save