diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index 20ea143..c453313 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -6,7 +6,6 @@ use std::io; use termion; use termion::event::{Event, Key}; use termion::input::TermRead; -use termion::color; use editor::Editor; use formatter::{block_index_and_offset, LineFormatter, LINE_BLOCK_LENGTH}; diff --git a/src/term_ui/screen.rs b/src/term_ui/screen.rs index b522bf6..14f1822 100644 --- a/src/term_ui/screen.rs +++ b/src/term_ui/screen.rs @@ -62,18 +62,33 @@ impl Screen { let mut x = 0; let mut last_style = Style(Color::Black, Color::Black); let mut left_x = 0; + tmp_string.clear(); + tmp_string.push_str(&format!("{}", last_style)); while x < self.w { if let Some((style, ref text)) = buf[y * self.w + x] { + if style != last_style { + tmp_string.push_str(&format!("{}", style)); + last_style = style; + } + tmp_string.push_str(text); + x += 1; + } else { write!( self.out.borrow_mut(), - "{}{}{}", - termion::cursor::Goto((x + 1) as u16, (y + 1) as u16), - style, - text, + "{}{}", + termion::cursor::Goto((left_x + 1) as u16, (y + 1) as u16), + tmp_string, ).unwrap(); + x += 1; + left_x = x; } - x += 1; } + write!( + self.out.borrow_mut(), + "{}{}", + termion::cursor::Goto((left_x + 1) as u16, (y + 1) as u16), + tmp_string, + ).unwrap(); } self.out.borrow_mut().flush().unwrap(); }