feat(editor): refresh screen when starting editor

This commit is contained in:
Harsh Shandilya 2022-08-07 17:29:56 +05:30
parent f8a516fb4b
commit 9afeaeeb15
No known key found for this signature in database
GPG Key ID: 366D7BBAD1031E80

View File

@ -1,4 +1,4 @@
use std::io::{self, stdout};
use std::io::{self, stdout, Write};
use std::result::Result;
use termion::{event::Key, input::TermRead, raw::IntoRawMode};
@ -11,12 +11,15 @@ impl Editor {
pub fn run(&mut self) {
let _stdout = stdout().into_raw_mode().unwrap();
loop {
if let Err(error) = self.process_keypress() {
if let Err(error) = self.refresh_screen() {
panic!("{}", error);
};
if self.should_quit {
break;
}
if let Err(error) = self.process_keypress() {
panic!("{}", error);
};
}
}
@ -28,6 +31,11 @@ impl Editor {
};
Ok(())
}
fn refresh_screen(&self) -> Result<(), io::Error> {
print!("{}", termion::clear::All);
io::stdout().flush()
}
}
fn read_key() -> Result<Key, io::Error> {