aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorOmnikar2021-12-01 22:59:23 +0000
committerBlaž Hrastnik2022-04-20 02:37:23 +0000
commite6b865ed0b1b77934733d86b59d60870e9f5881f (patch)
treef090ee3a7078b3109102abb3f555acb241ef4cd5 /helix-view
parent94eba0e66aa193c093b1d7eefc0e21391cb2485f (diff)
allow whitespace to be rendered
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs87
1 files changed, 86 insertions, 1 deletions
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<u16>,
+ #[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<WhitespaceRenderValue>,
+ space: Option<WhitespaceRenderValue>,
+ tab: Option<WhitespaceRenderValue>,
+ newline: Option<WhitespaceRenderValue>,
+ },
+}
+
+#[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<Config>),
}
#[derive(Debug, Clone)]