rs-kilo/src/main.rs

36 lines
840 B
Rust

mod editor;
mod helpers;
use crate::editor::Editor;
use crate::helpers::*;
use libc::STDIN_FILENO;
use std::io::Error;
use std::result::Result;
fn main() -> Result<(), Error> {
// Save original terminal flags
let original_termios = get_termios(STDIN_FILENO);
// Disable canonical/"cooked" terminal mode
enable_raw_mode();
// Initialize the editor
let mut editor = Editor::new();
// 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()?;
if editor.process_keypress().is_none() {
break;
}
}
// Restore previous terminal flags before exit
disable_raw_mode(&original_termios);
Ok(())
}