Only call editor::refresh_screen on a key press

This commit is contained in:
Timothy Warren 2019-09-17 10:34:17 -04:00
parent cac43aeba9
commit 6497111427
2 changed files with 19 additions and 10 deletions

View File

@ -737,7 +737,7 @@ impl Editor {
loop {
self.set_status_message(&format!("{} {}", prompt, buffer));
self.refresh_screen();
self.refresh_screen(false);
let ch = self.read_key();
if ch.is_some() {
@ -1053,7 +1053,7 @@ impl Editor {
&self.filename
};
let modified = if self.dirty > 0 { "(modified}" } else { "" };
let modified = if self.dirty > 0 { "(modified)" } else { "" };
let mut left_message = format!("{:.80} - {} lines {}", filename, self.rows.len(), modified);
let file_type = match &self.syntax {
@ -1094,12 +1094,16 @@ impl Editor {
}
}
pub fn refresh_screen(&mut self) {
pub fn refresh_screen(&mut self, skip_refresh: bool) {
if skip_refresh {
return;
}
self.scroll();
self.output_buffer.clear();
// Hide cursor, reposition cursor
// self.append_out("\x1b[?25l");
self.append_out("\x1b[?25l");
self.append_out("\x1b[H");
self.draw_rows();
@ -1113,7 +1117,7 @@ impl Editor {
self.append_out(&cursor_code.as_str());
// Show cursor
// self.append_out("\x1b[?25h");
self.append_out("\x1b[?25h");
let stdout = io::stdout();
let mut handle = stdout.lock();

View File

@ -38,19 +38,24 @@ fn main() -> Result<(), Error> {
editor.set_status_message("HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find");
let mut skip_refresh: bool = false;
// Main input loop. Editor::process_keypress uses an Option Enum as a sentinel.
// `None` is returned on a quit action, in other cases, `Some(())` is returned,
// continuing the loop
loop {
editor.refresh_screen();
editor.refresh_screen(skip_refresh);
match editor.process_keypress() {
Some(key) => {
match key {
editor::KeyCode::OtherKey('\0') => (),
// Just for debugging
_ => (), //println!("{:?}\r\n", key)
editor::KeyCode::OtherKey('\0') => {
skip_refresh = true;
}
_ => {
skip_refresh = false;
//println!("{:?}\r\n", key)
}
}
}
None => break,