Skip to content

Commit

Permalink
feat(whitespace): add whitespace rendering and custom char rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
metiftikci committed Oct 26, 2023
1 parent fc07e69 commit ffbb37f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/buffer/options.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
use std::collections::HashMap;

pub struct BufferOptions {
pub show_info_column: bool,
pub show_border: bool,
pub chars: HashMap<char, char>,
}

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
}
}
2 changes: 1 addition & 1 deletion src/screen/print_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
Expand Down

0 comments on commit ffbb37f

Please sign in to comment.