From e6b865ed0b1b77934733d86b59d60870e9f5881f Mon Sep 17 00:00:00 2001 From: Omnikar Date: Wed, 1 Dec 2021 17:59:23 -0500 Subject: allow whitespace to be rendered Co-authored-by: Michael Davis --- helix-view/src/editor.rs | 87 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'helix-view') diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 0c2fad2b..79775c89 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -148,6 +148,8 @@ pub struct Config { pub lsp: LspConfig, /// Column numbers at which to draw the rulers. Default to `[]`, meaning no rulers. pub rulers: Vec, + #[serde(default)] + pub whitespace: WhitespaceConfig, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] @@ -263,6 +265,88 @@ impl std::str::FromStr for GutterType { } } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(default)] +pub struct WhitespaceConfig { + pub render: WhitespaceRender, + pub characters: WhitespaceCharacters, +} + +impl Default for WhitespaceConfig { + fn default() -> Self { + Self { + render: WhitespaceRender::Basic(WhitespaceRenderValue::None), + characters: WhitespaceCharacters::default(), + } + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(untagged, rename_all = "kebab-case")] +pub enum WhitespaceRender { + Basic(WhitespaceRenderValue), + Specific { + default: Option, + space: Option, + tab: Option, + newline: Option, + }, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum WhitespaceRenderValue { + None, + // TODO + // Selection, + All, +} + +impl WhitespaceRender { + pub fn space(&self) -> WhitespaceRenderValue { + match *self { + Self::Basic(val) => val, + Self::Specific { default, space, .. } => { + space.or(default).unwrap_or(WhitespaceRenderValue::None) + } + } + } + pub fn tab(&self) -> WhitespaceRenderValue { + match *self { + Self::Basic(val) => val, + Self::Specific { default, tab, .. } => { + tab.or(default).unwrap_or(WhitespaceRenderValue::None) + } + } + } + pub fn newline(&self) -> WhitespaceRenderValue { + match *self { + Self::Basic(val) => val, + Self::Specific { + default, newline, .. + } => newline.or(default).unwrap_or(WhitespaceRenderValue::None), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct WhitespaceCharacters { + pub space: char, + pub tab: char, + pub newline: char, +} + +impl Default for WhitespaceCharacters { + fn default() -> Self { + Self { + space: '·', // U+00B7 + tab: '→', // U+2192 + newline: '⏎', // U+23CE + } + } +} + impl Default for Config { fn default() -> Self { Self { @@ -288,6 +372,7 @@ impl Default for Config { search: SearchConfig::default(), lsp: LspConfig::default(), rulers: Vec::new(), + whitespace: WhitespaceConfig::default(), } } } @@ -366,7 +451,7 @@ pub struct Editor { #[derive(Debug, Clone)] pub enum ConfigEvent { Refresh, - Update(Config), + Update(Box), } #[derive(Debug, Clone)] -- cgit v1.2.3-70-g09d2