Skip to content

Commit

Permalink
editor refresh screen added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Mar 5, 2024
1 parent f5e079c commit ad67ace
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
use crossterm::{
cursor::MoveTo,
event::{read, Event::Key, KeyCode, KeyEvent, KeyModifiers},
terminal::{disable_raw_mode, enable_raw_mode},
terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType},
};

fn main() {
let _ = enable_raw_mode();
while editor_process_keypress() {}

editor_refresh_screen();
loop {
editor_refresh_screen();
if !editor_process_keypress() {
break;
}
}
editor_refresh_screen();

let _ = disable_raw_mode();
}

fn die<S: Into<String>>(message: S) {
let _ = disable_raw_mode();
editor_refresh_screen();
eprintln!("{}: {}", message.into(), std::io::Error::last_os_error());
std::process::exit(1);
}

fn editor_refresh_screen() {
print!("{} {}", Clear(ClearType::All), MoveTo(0, 0));
editor_draw_rows();
print!("{}", MoveTo(0, 0));
}

fn editor_draw_rows() {
for _ in 0..24 {
println!("~\r");
}
}

fn editor_read_key() -> Result<KeyEvent, ()> {
if let Ok(Key(key)) = read() {
Ok(key)
Expand Down

0 comments on commit ad67ace

Please sign in to comment.