Made the screen buffer implemention way faster.
It's in a pretty good place now, I think. Although its memory usage could be improved with a small string type.
This commit is contained in:
parent
945505c5ff
commit
0a309fab1a
|
@ -6,7 +6,6 @@ use std::io;
|
||||||
use termion;
|
use termion;
|
||||||
use termion::event::{Event, Key};
|
use termion::event::{Event, Key};
|
||||||
use termion::input::TermRead;
|
use termion::input::TermRead;
|
||||||
use termion::color;
|
|
||||||
|
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use formatter::{block_index_and_offset, LineFormatter, LINE_BLOCK_LENGTH};
|
use formatter::{block_index_and_offset, LineFormatter, LINE_BLOCK_LENGTH};
|
||||||
|
|
|
@ -62,19 +62,34 @@ impl Screen {
|
||||||
let mut x = 0;
|
let mut x = 0;
|
||||||
let mut last_style = Style(Color::Black, Color::Black);
|
let mut last_style = Style(Color::Black, Color::Black);
|
||||||
let mut left_x = 0;
|
let mut left_x = 0;
|
||||||
|
tmp_string.clear();
|
||||||
|
tmp_string.push_str(&format!("{}", last_style));
|
||||||
while x < self.w {
|
while x < self.w {
|
||||||
if let Some((style, ref text)) = buf[y * self.w + x] {
|
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!(
|
write!(
|
||||||
self.out.borrow_mut(),
|
self.out.borrow_mut(),
|
||||||
"{}{}{}",
|
"{}{}",
|
||||||
termion::cursor::Goto((x + 1) as u16, (y + 1) as u16),
|
termion::cursor::Goto((left_x + 1) as u16, (y + 1) as u16),
|
||||||
style,
|
tmp_string,
|
||||||
text,
|
|
||||||
).unwrap();
|
).unwrap();
|
||||||
}
|
|
||||||
x += 1;
|
x += 1;
|
||||||
|
left_x = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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();
|
self.out.borrow_mut().flush().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user