rs-kilo/src/main.rs

52 lines
1.2 KiB
Rust
Raw Normal View History

2019-08-22 14:25:18 -04:00
mod editor;
mod helpers;
2019-08-30 16:17:06 -04:00
use crate::editor::Editor;
use crate::helpers::*;
use libc::STDIN_FILENO;
2019-08-27 12:22:19 -04:00
use std::env;
use std::io::Error;
use std::result::Result;
2019-08-22 14:25:18 -04:00
fn main() -> Result<(), Error> {
2019-08-27 12:22:19 -04:00
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();
2019-08-22 14:25:18 -04:00
// Initialize the editor
2019-08-22 16:44:47 -04:00
let mut editor = Editor::new();
2019-08-22 14:25:18 -04:00
2019-08-27 12:22:19 -04:00
// Open the file if specified, from the command line
if args.len() >= 2 {
editor.open(&args[1])?;
}
2019-09-03 16:19:19 -04:00
editor.set_status_message("HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find");
2019-08-29 14:13:09 -04:00
// 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
2019-08-23 16:46:04 -04:00
loop {
2019-08-30 16:17:06 -04:00
editor.refresh_screen();
2019-08-23 16:46:04 -04:00
let key = editor.process_keypress();
if key.is_none() {
2019-08-23 16:46:04 -04:00
break;
}
/*match key.unwrap() {
2019-08-30 16:17:06 -04:00
editor::EditorKey::OtherKey('\0') => (),
_ => println!("{:?}\r\n", key)
} */
2019-08-21 16:46:14 -04:00
}
// Restore previous terminal flags before exit
disable_raw_mode(&original_termios);
Ok(())
2019-08-21 16:46:14 -04:00
}