Only call editor::refresh_screen on a key press
This commit is contained in:
parent
cac43aeba9
commit
6497111427
@ -737,7 +737,7 @@ impl Editor {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
self.set_status_message(&format!("{} {}", prompt, buffer));
|
self.set_status_message(&format!("{} {}", prompt, buffer));
|
||||||
self.refresh_screen();
|
self.refresh_screen(false);
|
||||||
|
|
||||||
let ch = self.read_key();
|
let ch = self.read_key();
|
||||||
if ch.is_some() {
|
if ch.is_some() {
|
||||||
@ -1053,7 +1053,7 @@ impl Editor {
|
|||||||
&self.filename
|
&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 mut left_message = format!("{:.80} - {} lines {}", filename, self.rows.len(), modified);
|
||||||
let file_type = match &self.syntax {
|
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.scroll();
|
||||||
self.output_buffer.clear();
|
self.output_buffer.clear();
|
||||||
|
|
||||||
// Hide cursor, reposition cursor
|
// Hide cursor, reposition cursor
|
||||||
// self.append_out("\x1b[?25l");
|
self.append_out("\x1b[?25l");
|
||||||
self.append_out("\x1b[H");
|
self.append_out("\x1b[H");
|
||||||
|
|
||||||
self.draw_rows();
|
self.draw_rows();
|
||||||
@ -1113,7 +1117,7 @@ impl Editor {
|
|||||||
self.append_out(&cursor_code.as_str());
|
self.append_out(&cursor_code.as_str());
|
||||||
|
|
||||||
// Show cursor
|
// Show cursor
|
||||||
// self.append_out("\x1b[?25h");
|
self.append_out("\x1b[?25h");
|
||||||
|
|
||||||
let stdout = io::stdout();
|
let stdout = io::stdout();
|
||||||
let mut handle = stdout.lock();
|
let mut handle = stdout.lock();
|
||||||
|
15
src/main.rs
15
src/main.rs
@ -38,19 +38,24 @@ fn main() -> Result<(), Error> {
|
|||||||
|
|
||||||
editor.set_status_message("HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find");
|
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.
|
// 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,
|
// `None` is returned on a quit action, in other cases, `Some(())` is returned,
|
||||||
// continuing the loop
|
// continuing the loop
|
||||||
loop {
|
loop {
|
||||||
editor.refresh_screen();
|
editor.refresh_screen(skip_refresh);
|
||||||
|
|
||||||
match editor.process_keypress() {
|
match editor.process_keypress() {
|
||||||
Some(key) => {
|
Some(key) => {
|
||||||
match key {
|
match key {
|
||||||
editor::KeyCode::OtherKey('\0') => (),
|
editor::KeyCode::OtherKey('\0') => {
|
||||||
|
skip_refresh = true;
|
||||||
// Just for debugging
|
}
|
||||||
_ => (), //println!("{:?}\r\n", key)
|
_ => {
|
||||||
|
skip_refresh = false;
|
||||||
|
//println!("{:?}\r\n", key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => break,
|
None => break,
|
||||||
|
Loading…
Reference in New Issue
Block a user