From 6b4ce204f94d52fcc56593968e285ccf93532beb Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Mon, 2 Jan 2023 21:50:53 +0100 Subject: [PATCH 1/2] Gutter character configuration. This commit adds support for configuring the gutter characters. Currently, three flavours are supported: - Diagnostics, with a string. - Breakpoints, with two strings (one for verified and one for non-verified breakpoints). - And diffs, with three strings (add, remove, change). --- helix-view/src/editor.rs | 69 ++++++++++++++++++++++++++++++++++++++++ helix-view/src/gutter.rs | 23 ++++++++++---- helix-view/src/view.rs | 2 ++ 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index eef4a3f99e91..76ec8ce41faf 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -78,6 +78,12 @@ pub struct GutterConfig { pub layout: Vec, /// Options specific to the "line-numbers" gutter pub line_numbers: GutterLineNumbersConfig, + /// Options specific to the "diagnostics" gutter. + pub diagnostics: DiagnosticsGutterConfig, + /// Options specific to the “breakpoints” gutter. + pub breakpoints: BreakpointsGutterConfig, + /// Options specific to the “diff” gutter. + pub diff: DiffGutterConfig, } impl Default for GutterConfig { @@ -91,6 +97,9 @@ impl Default for GutterConfig { GutterType::Diff, ], line_numbers: GutterLineNumbersConfig::default(), + diagnostics: DiagnosticsGutterConfig::default(), + breakpoints: BreakpointsGutterConfig::default(), + diff: DiffGutterConfig::default(), } } } @@ -569,6 +578,66 @@ impl std::str::FromStr for GutterType { } } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct DiagnosticsGutterConfig { + pub characters: String, +} + +impl Default for DiagnosticsGutterConfig { + fn default() -> Self { + Self { + characters: "●".to_owned(), + } + } +} + +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct BreakpointsGutterConfig { + pub characters: BreakpointsGutterCharacters, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct BreakpointsGutterCharacters { + pub verified: String, + pub other: String, +} + +impl Default for BreakpointsGutterCharacters { + fn default() -> Self { + Self { + verified: "▲".to_owned(), + other: "⊚".to_owned(), + } + } +} + +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct DiffGutterConfig { + pub characters: DiffGutterCharacters, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct DiffGutterCharacters { + pub add: String, + pub remove: String, + pub change: String, +} + +impl Default for DiffGutterCharacters { + fn default() -> Self { + Self { + add: "▍".to_owned(), + remove: "▔".to_owned(), + change: "▍".to_owned(), + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(default)] pub struct WhitespaceConfig { diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index c1b5e2b16112..3f282c800241 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -46,7 +46,7 @@ impl GutterType { } pub fn diagnostic<'doc>( - _editor: &'doc Editor, + editor: &'doc Editor, doc: &'doc Document, _view: &View, theme: &Theme, @@ -73,7 +73,8 @@ pub fn diagnostic<'doc>( // This unwrap is safe because the iterator cannot be empty as it contains at least the item found by the binary search. let diagnostic = diagnostics_on_line.max_by_key(|d| d.severity).unwrap(); - write!(out, "●").unwrap(); + out.write_str(&editor.config().gutters.diagnostics.characters) + .unwrap(); return Some(match diagnostic.severity { Some(Severity::Error) => error, Some(Severity::Warning) | None => warning, @@ -86,7 +87,7 @@ pub fn diagnostic<'doc>( } pub fn diff<'doc>( - _editor: &'doc Editor, + editor: &'doc Editor, doc: &'doc Document, _view: &View, theme: &Theme, @@ -116,12 +117,13 @@ pub fn diff<'doc>( return None; } + let chars = &editor.config().gutters.diff.characters; let (icon, style) = if hunk.is_pure_insertion() { - ("▍", added) + (&chars.add, added) } else if hunk.is_pure_removal() { - ("▔", deleted) + (&chars.remove, deleted) } else { - ("▍", modified) + (&chars.change, modified) }; write!(out, "{}", icon).unwrap(); @@ -268,7 +270,12 @@ pub fn breakpoints<'doc>( } }; - let sym = if breakpoint.verified { "▲" } else { "⊚" }; + let chars = &editor.config().gutters.breakpoints.characters; + let sym = if breakpoint.verified { + &chars.verified + } else { + &chars.other + }; write!(out, "{}", sym).unwrap(); Some(style) }) @@ -333,6 +340,7 @@ mod tests { let gutters = GutterConfig { layout: vec![GutterType::Diagnostics, GutterType::LineNumbers], line_numbers: GutterLineNumbersConfig { min_width: 10 }, + ..GutterConfig::default() }; let mut view = View::new(DocumentId::default(), gutters); @@ -351,6 +359,7 @@ mod tests { let gutters = GutterConfig { layout: vec![GutterType::Diagnostics, GutterType::LineNumbers], line_numbers: GutterLineNumbersConfig { min_width: 1 }, + ..GutterConfig::default() }; let mut view = View::new(DocumentId::default(), gutters); diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index abcf9a169860..8196b6f8609c 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -484,6 +484,7 @@ mod tests { GutterConfig { layout: vec![GutterType::Diagnostics], line_numbers: GutterLineNumbersConfig::default(), + ..GutterConfig::default() }, ); view.area = Rect::new(40, 40, 40, 40); @@ -507,6 +508,7 @@ mod tests { GutterConfig { layout: vec![], line_numbers: GutterLineNumbersConfig::default(), + ..GutterConfig::default() }, ); view.area = Rect::new(40, 40, 40, 40); From b280008f1b441db669b902fbfbab395c838d353e Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Wed, 4 Jan 2023 20:34:22 +0100 Subject: [PATCH 2/2] Add configuration doc for gutters characters. --- book/src/configuration.md | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index ab229f772a1c..173991911d9e 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -284,7 +284,7 @@ layout = ["diff", "diagnostics", "line-numbers", "spacer"] #### `[editor.gutters.line-numbers]` Section -Options for the line number gutter +Options for the line number gutter. | Key | Description | Default | | --- | --- | --- | @@ -297,13 +297,36 @@ Example: min-width = 1 ``` -#### `[editor.gutters.diagnotics]` Section +#### `[editor.gutters.diagnostics]` Section -Currently unused +Options for the diagnostics gutter. + +| Key | Description | Default | +| --- | --- | --- | +| `characters` | Characters to be used in the gutter column | `"●"` | + +#### `[editor.gutters.breakpoints]` Section + +Options for the breakpoints gutter. + +| Key | Description | Default | +| --- | --- | --- | +| `characters.verified` | Characters to be used in the gutter column for verified breakpoints | `"▲"` | +| `characters.other` | Characters to be used in the gutter column for other breakpoints | `"⊚"` | + +Alternatively, you can use the `[editor.gutters.breakpoints.characters]` section +and use the `verified` and `other` keys. #### `[editor.gutters.diff]` Section -Currently unused +| Key | Description | Default | +| --- | --- | --- | +| `characters.add` | Characters to be used in the gutter column for code additions | `"▍"` | +| `characters.remove` | Characters to be used in the gutter column for code deletions | `"▔"` | +| `characters.change` | Characters to be used in the gutter column for code changes | `"▍"` | + +Alternatively, you can use the `[editor.gutters.diff.characters]` section +and use the `add`, `remove` and `change` keys. #### `[editor.gutters.spacer]` Section