rs-kilo/src/main.rs

52 lines
1.2 KiB
Rust

mod editor;
mod helpers;
use crate::editor::{Editor, EditorKey};
use crate::helpers::*;
use libc::STDIN_FILENO;
use std::env;
use std::io::Error;
use std::result::Result;
fn main() -> Result<(), Error> {
let args: Vec<String> = env::args().collect();
// 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();
// Open the file if specified, from the command line
if args.len() >= 2 {
editor.open(&args[1])?;
}
editor.set_status_message("HELP: Ctrl-S = save | Ctrl-Q = quit");
// 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()?;
let key = editor.process_keypress();
if key.is_none() {
break;
}
/*match key.unwrap() {
EditorKey::OtherKey('\0') => (),
_ => println!("{:?}\r\n", key)
} */
}
// Restore previous terminal flags before exit
disable_raw_mode(&original_termios);
Ok(())
}