2019-08-22 14:25:18 -04:00
|
|
|
mod editor;
|
|
|
|
mod helpers;
|
|
|
|
|
2019-08-22 16:44:47 -04:00
|
|
|
use crate::editor::Editor;
|
2019-08-23 13:34:00 -04:00
|
|
|
use crate::helpers::*;
|
2019-08-22 14:25:18 -04:00
|
|
|
|
2019-08-22 16:44:47 -04:00
|
|
|
fn main() {
|
2019-08-23 14:57:26 -04:00
|
|
|
// Save original terminal flags
|
2019-08-23 13:34:00 -04:00
|
|
|
let original_termios = get_termios(STDIN_FILENO);
|
|
|
|
|
2019-08-23 14:57:26 -04:00
|
|
|
// Disable canonical/"cooked" terminal mode
|
|
|
|
enable_raw_mode();
|
2019-08-22 14:25:18 -04:00
|
|
|
|
2019-08-23 14:57:26 -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-23 14:57:26 -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-22 16:44:47 -04:00
|
|
|
while editor.process_keypress().is_some() {
|
|
|
|
// loop
|
2019-08-21 16:46:14 -04:00
|
|
|
}
|
2019-08-23 13:34:00 -04:00
|
|
|
|
2019-08-23 14:57:26 -04:00
|
|
|
// Restore previous terminal flags before exit
|
|
|
|
disable_raw_mode(&original_termios);
|
2019-08-21 16:46:14 -04:00
|
|
|
}
|