diff --git a/src/buffer/options.rs b/src/buffer/options.rs index 467b124..c66d329 100644 --- a/src/buffer/options.rs +++ b/src/buffer/options.rs @@ -17,19 +17,3 @@ impl Default for BufferOptions { 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 81a903b..502e879 100644 --- a/src/screen/print_buffer.rs +++ b/src/screen/print_buffer.rs @@ -109,11 +109,11 @@ impl Screen { Style::new(T.info_column_fg, T.info_column_bg), ); } - self.print_text( + self.print_buffer_text( + &buffer.options.chars, buffer.area.y + y, buffer.text_area.x, - &buffer.options.replace_chars(&text), - Style::new(T.text_fg, T.text_bg), + &text, ); } Err(_) => { diff --git a/src/screen/print_text.rs b/src/screen/print_text.rs index c05115d..b1d2d63 100644 --- a/src/screen/print_text.rs +++ b/src/screen/print_text.rs @@ -1,4 +1,6 @@ -use crate::{core::style::Style, screen::Screen}; +use std::collections::HashMap; + +use crate::{core::style::Style, screen::Screen, theme::THEME_ONE as T}; impl Screen { pub fn print_text(&mut self, row: u16, column: u16, text: &str, style: Style) { @@ -13,4 +15,29 @@ impl Screen { column_index += 1; } } + + pub fn print_buffer_text( + &mut self, + replace_chars: &HashMap, + row: u16, + column: u16, + text: &str, + ) { + let columns = self.rows.get_mut(row as usize).unwrap(); + let mut column_index = column as usize; + for c in text.chars() { + let cell = columns.get_mut(column_index).unwrap(); + cell.char = if let Some(replace_char) = replace_chars.get(&c) { + replace_char.clone() + } else { + c + }; + cell.style = if c == ' ' { + Style::new(T.text_whitespace_fg, T.text_whitespace_bg) + } else { + Style::new(T.text_fg, T.text_bg) + }; + column_index += 1; + } + } } diff --git a/src/theme.rs b/src/theme.rs index ff5cbfe..41ea29c 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -16,6 +16,8 @@ pub struct Theme { pub text_bg: Color, pub text_selected_fg: Color, pub text_selected_bg: Color, + pub text_whitespace_fg: Color, + pub text_whitespace_bg: Color, pub text_finded_fg: Color, pub text_finded_bg: Color, @@ -61,6 +63,8 @@ pub const THEME_ONE: Theme = Theme { text_bg: SILVER, text_selected_fg: WHITE, text_selected_bg: GRAY, + text_whitespace_fg: LIGHT_GRAY, + text_whitespace_bg: SILVER, text_finded_fg: RED, text_finded_bg: GRAY,