Allow to use character to draw rulers

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

@ -42,6 +42,7 @@
| `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` |
| `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` |

@ -307,6 +307,7 @@ These scopes are used for theming the editor interface:
| `ui.text.inactive` | Same as `ui.text` but when the text is inactive (e.g. suggestions) | | `ui.text.inactive` | Same as `ui.text` but when the text is inactive (e.g. suggestions) |
| `ui.text.info` | The key: command text in `ui.popup.info` boxes | | `ui.text.info` | The key: command text in `ui.popup.info` boxes |
| `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][editor-section]) | | `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][editor-section]) |
| `ui.virtual.ruler.char` | Ruler columns, ([only if `editor.ruler-char` is set][editor-section] |
| `ui.virtual.whitespace` | Visible whitespace characters | | `ui.virtual.whitespace` | Visible whitespace characters |
| `ui.virtual.indent-guide` | Vertical indent width guides | | `ui.virtual.indent-guide` | Vertical indent width guides |
| `ui.virtual.inlay-hint` | Default style for inlay hints of all kinds | | `ui.virtual.inlay-hint` | Default style for inlay hints of all kinds |

@ -201,6 +201,9 @@ impl EditorView {
inline_diagnostic_config, inline_diagnostic_config,
config.end_of_line_diagnostics, config.end_of_line_diagnostics,
)); ));
Self::render_rulers(editor, doc, view, inner, surface, theme);
render_document( render_document(
surface, surface,
inner, inner,
@ -212,7 +215,6 @@ impl EditorView {
theme, theme,
decorations, decorations,
); );
Self::render_rulers(editor, doc, view, inner, surface, theme);
// if we're not at the edge of the screen, draw a right border // if we're not at the edge of the screen, draw a right border
if viewport.right() != view.area.right() { if viewport.right() != view.area.right() {
@ -252,8 +254,15 @@ 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 theme_key = match &editor_ruler_char {
None => "ui.virtual.ruler",
Some(_) => "ui.virtual.ruler.char",
};
let ruler_theme = theme let ruler_theme = theme
.try_get("ui.virtual.ruler") .try_get(theme_key)
.unwrap_or_else(|| Style::default().bg(Color::Red)); .unwrap_or_else(|| Style::default().bg(Color::Red));
let rulers = doc let rulers = doc
@ -270,7 +279,15 @@ impl EditorView {
.filter_map(|ruler| ruler.checked_sub(1 + view_offset.horizontal_offset as u16)) .filter_map(|ruler| ruler.checked_sub(1 + view_offset.horizontal_offset as u16))
.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| surface.set_style(area, ruler_theme)) .for_each(|area| {
if let Some(ruler_char) = &editor_ruler_char {
for y in area.y..area.height {
surface.set_string(area.x, y, ruler_char, ruler_theme)
}
} else {
surface.set_style(area, ruler_theme)
}
})
} }
fn viewport_byte_range( fn viewport_byte_range(

@ -314,6 +314,8 @@ 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.
pub ruler_char: Option<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
@ -963,6 +965,7 @@ 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,
whitespace: WhitespaceConfig::default(), whitespace: WhitespaceConfig::default(),
bufferline: BufferLine::default(), bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(), indent_guides: IndentGuidesConfig::default(),

Loading…
Cancel
Save