From ffbb37f5b7da3e0f4381ab6f7088d4da863aeec9 Mon Sep 17 00:00:00 2001 From: metiftikci Date: Thu, 26 Oct 2023 22:46:31 +0300 Subject: [PATCH] feat(whitespace): add whitespace rendering and custom char rendering --- src/buffer/options.rs | 24 +++++++++++++++++++++++- src/screen/print_buffer.rs | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/buffer/options.rs b/src/buffer/options.rs index c39dfa1..467b124 100644 --- a/src/buffer/options.rs +++ b/src/buffer/options.rs @@ -1,13 +1,35 @@ +use std::collections::HashMap; + pub struct BufferOptions { pub show_info_column: bool, pub show_border: bool, + pub chars: HashMap, } impl Default for BufferOptions { fn default() -> Self { - Self { + let mut options = Self { show_info_column: true, show_border: false, + chars: HashMap::new(), + }; + options.chars.insert(' ', '•'); + options + } +} + +impl BufferOptions { + pub fn replace_chars(&self, text: &str) -> String { + let mut result = String::new(); + + for c in text.chars() { + if let Some(m) = self.chars.get(&c) { + result.push(m.clone()); + } else { + result.push(c); + } } + + result } } diff --git a/src/screen/print_buffer.rs b/src/screen/print_buffer.rs index 1282400..81a903b 100644 --- a/src/screen/print_buffer.rs +++ b/src/screen/print_buffer.rs @@ -112,7 +112,7 @@ impl Screen { self.print_text( buffer.area.y + y, buffer.text_area.x, - &text, + &buffer.options.replace_chars(&text), Style::new(T.text_fg, T.text_bg), ); }