mirror of
https://github.com/msfjarvis/text-editor.git
synced 2024-06-03 04:18:57 +05:30
feat(editor): refresh screen when starting editor
This commit is contained in:
parent
f8a516fb4b
commit
9afeaeeb15
|
@ -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> {
|
||||
|
|
Loading…
Reference in New Issue
Block a user