diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-05 17:08:40 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-05 17:08:56 -0500 |
commit | c416f8249399ab52bb6862aa734e789402e49f1c (patch) | |
tree | ca25e1146738e13faffa8592be8480c68cb41ee8 | |
parent | e83a099b061131e00ff378ed0dd58920dba1db25 (diff) |
remove use of enum for keystrokes and make a more elegant way to parse for keymappings
- add support for searching for files
-rw-r--r-- | src/joshuto.rs | 5 | ||||
-rw-r--r-- | src/joshuto/command.rs | 8 | ||||
-rw-r--r-- | src/joshuto/command/change_directory.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/cursor_move.rs | 24 | ||||
-rw-r--r-- | src/joshuto/command/file_operation.rs | 5 | ||||
-rw-r--r-- | src/joshuto/command/new_directory.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/search.rs | 66 | ||||
-rw-r--r-- | src/joshuto/keymap.rs | 126 | ||||
-rw-r--r-- | src/joshuto/keymapll.rs | 384 | ||||
-rw-r--r-- | src/joshuto/theme.rs | 160 | ||||
-rw-r--r-- | src/joshuto/ui.rs | 18 |
11 files changed, 353 insertions, 447 deletions
diff --git a/src/joshuto.rs b/src/joshuto.rs index 62ebb06..fa8f226 100644 --- a/src/joshuto.rs +++ b/src/joshuto.rs @@ -21,11 +21,8 @@ mod ui; mod unix; mod window; -mod keymapll; - use self::command::CommandKeybind; use self::command::JoshutoCommand; -use self::keymapll::Keycode; pub struct JoshutoContext<'a> { pub curr_path: path::PathBuf, @@ -200,7 +197,7 @@ fn recurse_get_keycommand<'a>(keymap: &'a HashMap<i32, CommandKeybind>) ncurses::update_panels(); ncurses::doupdate(); - if ch == Keycode::ESCAPE as i32 { + if ch == keymap::ESCAPE { None } else { match keymap.get(&ch) { diff --git a/src/joshuto/command.rs b/src/joshuto/command.rs index 35a199d..0c44556 100644 --- a/src/joshuto/command.rs +++ b/src/joshuto/command.rs @@ -40,6 +40,9 @@ pub use self::file_operation::RenameFileMethod; mod new_directory; pub use self::new_directory::NewDirectory; +mod search; +pub use self::search::Search; + mod show_hidden; pub use self::show_hidden::ToggleHiddenFiles; @@ -117,7 +120,7 @@ pub fn from_args(args: &[&str]) -> Option<Box<dyn JoshutoCommand>> "open_file" => Some(Box::new(self::OpenFile::new())), "open_file_with" => Some(Box::new(self::OpenFileWith::new())), - "change_directory" => { + "cd" => { if args_len > 1 { let path = path::PathBuf::from(args[1]); Some(Box::new(self::ChangeDirectory::new(path))) @@ -192,7 +195,8 @@ pub fn from_args(args: &[&str]) -> Option<Box<dyn JoshutoCommand>> } Some(Box::new(self::RenameFile::new(method))) } - "new_directory" => Some(Box::new(self::NewDirectory::new())), + "mkdir" => Some(Box::new(self::NewDirectory::new())), + "search" => Some(Box::new(self::Search::new())), "select_files" => { let mut toggle = false; let mut all = false; diff --git a/src/joshuto/command/change_directory.rs b/src/joshuto/command/change_directory.rs index 6cb7e18..1ab787b 100644 --- a/src/joshuto/command/change_directory.rs +++ b/src/joshuto/command/change_directory.rs @@ -22,7 +22,7 @@ impl ChangeDirectory { path, } } - pub const fn command() -> &'static str { "change_directory" } + pub const fn command() -> &'static str { "cd" } } impl command::JoshutoCommand for ChangeDirectory {} diff --git a/src/joshuto/command/cursor_move.rs b/src/joshuto/command/cursor_move.rs index a9258e5..4f7c8c3 100644 --- a/src/joshuto/command/cursor_move.rs +++ b/src/joshuto/command/cursor_move.rs @@ -23,13 +23,13 @@ impl CursorMove { } pub fn command() -> &'static str { "cursor_move" } - pub fn cursor_move(movement: i32, context: &mut joshuto::JoshutoContext) + pub fn cursor_move(new_index: i32, context: &mut joshuto::JoshutoContext) { if let Some(ref mut curr_list) = context.curr_list { let curr_index = curr_list.index; let dir_len = curr_list.contents.len() as i32; - let mut new_index = curr_list.index + movement; + let mut new_index = new_index; if new_index <= 0 { new_index = 0; if curr_index <= 0 { @@ -91,7 +91,15 @@ impl std::fmt::Display for CursorMove { impl command::Runnable for CursorMove { fn execute(&self, context: &mut joshuto::JoshutoContext) { - Self::cursor_move(self.movement, context); + let mut movement: Option<i32> = None; + + if let Some(ref curr_list) = context.curr_list { + let curr_index = curr_list.index; + movement = Some(curr_index + self.movement); + } + if let Some(s) = movement { + CursorMove::cursor_move(s, context); + } } } @@ -123,8 +131,8 @@ impl command::Runnable for CursorMovePageUp { return; } - let half_page = -(context.views.mid_win.cols / 2); - movement = Some(half_page); + let half_page = context.views.mid_win.cols / 2; + movement = Some(curr_index - half_page); } if let Some(s) = movement { CursorMove::cursor_move(s, context); @@ -162,7 +170,7 @@ impl command::Runnable for CursorMovePageDown { } let half_page = context.views.mid_win.cols / 2; - movement = Some(half_page); + movement = Some(curr_index + half_page); } if let Some(s) = movement { CursorMove::cursor_move(s, context); @@ -197,7 +205,7 @@ impl command::Runnable for CursorMoveHome { if curr_index <= 0 { return; } - movement = Some(-curr_index); + movement = Some(0); } if let Some(s) = movement { CursorMove::cursor_move(s, context); @@ -234,7 +242,7 @@ impl command::Runnable for CursorMoveEnd { if curr_index >= dir_len as i32 - 1 { return; } - movement = Some(dir_len as i32 - 1 - curr_index); + movement = Some(dir_len as i32 - 1); } if let Some(s) = movement { CursorMove::cursor_move(s, context); diff --git a/src/joshuto/command/file_operation.rs b/src/joshuto/command/file_operation.rs index 3a9bc85..4f2d534 100644 --- a/src/joshuto/command/file_operation.rs +++ b/src/joshuto/command/file_operation.rs @@ -11,12 +11,11 @@ use std::thread; use joshuto; use joshuto::command; +use joshuto::keymap; use joshuto::structs; use joshuto::ui; use joshuto::window; -use joshuto::keymapll::Keycode; - lazy_static! { static ref selected_files: sync::Mutex<Vec<path::PathBuf>> = sync::Mutex::new(vec![]); static ref fileop: sync::Mutex<FileOp> = sync::Mutex::new(FileOp::Copy); @@ -330,7 +329,7 @@ impl command::Runnable for DeleteFiles { ncurses::doupdate(); let ch = ncurses::wgetch(context.views.bot_win.win); - if ch == Keycode::LOWER_Y as i32 || ch == Keycode::ENTER as i32 { + if ch == 'y' as i32 || ch == keymap::ENTER as i32 { if let Some(s) = context.curr_list.as_mut() { if let Some(paths) = collect_selected_paths(s) { Self::remove_files(paths, &context.views.bot_win); diff --git a/src/joshuto/command/new_directory.rs b/src/joshuto/command/new_directory.rs index da9ec59..639e1b1 100644 --- a/src/joshuto/command/new_directory.rs +++ b/src/joshuto/command/new_directory.rs @@ -15,7 +15,7 @@ pub struct NewDirectory; impl NewDirectory { pub fn new() -> Self { NewDirectory } - pub fn command() -> &'static str { "new_directory" } + pub fn command() -> &'static str { "mkdir" } } impl command::JoshutoCommand for NewDirectory {} diff --git a/src/joshuto/command/search.rs b/src/joshuto/command/search.rs new file mode 100644 index 0000000..2496781 --- /dev/null +++ b/src/joshuto/command/search.rs @@ -0,0 +1,66 @@ +extern crate ncurses; + +use std; +use std::fmt; + +use joshuto; +use joshuto::ui; +use joshuto::window; + +use joshuto::command; + +#[derive(Debug)] +pub struct Search; + +impl Search { + pub fn new() -> Self { Search } + pub fn command() -> &'static str { "search" } +} + +impl command::JoshutoCommand for Search {} + +impl std::fmt::Display for Search { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result + { + write!(f, "{}", Self::command()) + } +} + +impl command::Runnable for Search { + fn execute(&self, context: &mut joshuto::JoshutoContext) + { + let mut term_rows: i32 = 0; + let mut term_cols: i32 = 0; + ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols); + + let win = window::JoshutoPanel::new(1, term_cols, (term_rows as usize - 1, 0)); + ncurses::keypad(win.win, true); + + const PROMPT: &str = ":search "; + ncurses::waddstr(win.win, PROMPT); + + win.move_to_top(); + ncurses::doupdate(); + + let mut index: Option<i32> = None; + + if let Some(user_input) = ui::get_str(&win, (0, PROMPT.len() as i32)) { + if let Some(curr_list) = context.curr_list.as_ref() { + for (i, dirent) in (&curr_list.contents).into_iter().enumerate() { + if dirent.file_name_as_string.contains(user_input.as_str()) { + index = Some(i as i32); + break; + } + } + } + } + + if let Some(index) = index { + command::CursorMove::cursor_move(index, context); + } + + win.destroy(); + ncurses::update_panels(); + ncurses::doupdate(); + } +} diff --git a/src/joshuto/keymap.rs b/src/joshuto/keymap.rs index 1b90f24..8623624 100644 --- a/src/joshuto/keymap.rs +++ b/src/joshuto/keymap.rs @@ -9,7 +9,6 @@ use std::process; use joshuto::command; use joshuto::command::*; -use joshuto::keymapll::Keycode; const MAP_COMMAND: &str = "map"; // const ALIAS_COMMAND: &str = "alias"; @@ -17,6 +16,11 @@ const MAP_COMMAND: &str = "map"; const COMMENT_DELIMITER: char = '#'; +pub const BACKSPACE: i32 = 0x7F; +pub const TAB: i32 = 0x9; +pub const ENTER: i32 = 0xA; +pub const ESCAPE: i32 = 0x1B; + /* #define KEY_ALT(x) KEY_F(60) + (x - 'A') */ #[derive(Debug)] @@ -32,93 +36,93 @@ impl JoshutoKeymap { // quit let command = CommandKeybind::SimpleKeybind( Box::new(command::Quit::new())); - keymaps.insert(Keycode::LOWER_Q as i32, command); + keymaps.insert('q' as i32, command); // up let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMove::new(-1))); - keymaps.insert(Keycode::UP as i32, command); + keymaps.insert(ncurses::KEY_UP, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMove::new(-1))); - keymaps.insert(Keycode::LOWER_K as i32, command); + keymaps.insert('k' as i32, command); // down let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMove::new(1))); - keymaps.insert(Keycode::DOWN as i32, command); + keymaps.insert(ncurses::KEY_DOWN, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMove::new(1))); - keymaps.insert(Keycode::LOWER_J as i32, command); + keymaps.insert('j' as i32, command); // left let command = CommandKeybind::SimpleKeybind( Box::new(command::ParentDirectory::new())); - keymaps.insert(Keycode::LEFT as i32, command); + keymaps.insert(ncurses::KEY_LEFT, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::ParentDirectory::new())); - keymaps.insert(Keycode::LOWER_H as i32, command); + keymaps.insert('h' as i32, command); // right let command = CommandKeybind::SimpleKeybind( Box::new(command::OpenFile::new())); - keymaps.insert(Keycode::RIGHT as i32, command); + keymaps.insert(ncurses::KEY_RIGHT, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::OpenFile::new())); - keymaps.insert(Keycode::LOWER_L as i32, command); + keymaps.insert('l' as i32, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::OpenFile::new())); - keymaps.insert(Keycode::ENTER as i32, command); + keymaps.insert(ENTER, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::OpenFileWith::new())); - keymaps.insert(Keycode::LOWER_R as i32, command); + keymaps.insert('r' as i32, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMovePageUp::new())); - keymaps.insert(Keycode::PPAGE as i32, command); + keymaps.insert(ncurses::KEY_PPAGE, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMovePageDown::new())); - keymaps.insert(Keycode::NPAGE as i32, command); + keymaps.insert(ncurses::KEY_NPAGE, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMoveHome::new())); - keymaps.insert(Keycode::HOME as i32, command); + keymaps.insert(ncurses::KEY_HOME, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::CursorMoveEnd::new())); - keymaps.insert(Keycode::END as i32, command); + keymaps.insert(ncurses::KEY_END, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::DeleteFiles::new())); - keymaps.insert(Keycode::DELETE as i32, command); + keymaps.insert(ncurses::KEY_DC, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::RenameFile::new(command::RenameFileMethod::Append))); - keymaps.insert(Keycode::LOWER_A as i32, command); + keymaps.insert('a' as i32, command); { let mut subkeymap: HashMap<i32, CommandKeybind> = HashMap::new(); let command = CommandKeybind::SimpleKeybind( Box::new(command::ToggleHiddenFiles::new())); - subkeymap.insert(Keycode::LOWER_H as i32, command); + subkeymap.insert('h' as i32, command); let command = CommandKeybind::CompositeKeybind(subkeymap); - keymaps.insert(Keycode::LOWER_Z as i32, command); + keymaps.insert('z' as i32, command); } { let mut subkeymap: HashMap<i32, CommandKeybind> = HashMap::new(); let command = CommandKeybind::SimpleKeybind( Box::new(command::CutFiles::new())); - subkeymap.insert(Keycode::LOWER_D as i32, command); + subkeymap.insert('d' as i32, command); let command = CommandKeybind::SimpleKeybind( Box::new(command::DeleteFiles::new())); - subkeymap.insert(Keycode::UPPER_D as i32, command); + subkeymap.insert('D' as i32, command); let command = CommandKeybind::CompositeKeybind(subkeymap); - keymaps.insert(Keycode::LOWER_D as i32, command); + keymaps.insert('d' as i32, command); } { @@ -126,10 +130,10 @@ impl JoshutoKeymap { let command = CommandKeybind::SimpleKeybind( Box::new(command::CopyFiles::new())); - subkeymap.insert(Keycode::LOWER_Y as i32, command); + subkeymap.insert('y' as i32, command); let command = CommandKeybind::CompositeKeybind(subkeymap); - keymaps.insert(Keycode::LOWER_Y as i32, command); + keymaps.insert('y' as i32, command); } { @@ -138,26 +142,26 @@ impl JoshutoKeymap { let options = fs_extra::dir::CopyOptions::new(); let command = CommandKeybind::SimpleKeybind( Box::new(command::PasteFiles::new(options))); - subkeymap.insert(Keycode::LOWER_P as i32, command); + subkeymap.insert('p' as i32, command); let mut options = fs_extra::dir::CopyOptions::new(); options.overwrite = true; let command = CommandKeybind::SimpleKeybind( Box::new(command::PasteFiles::new(options))); - subkeymap.insert(Keycode::LOWER_O as i32, command); + subkeymap.insert('o' as i32, command); let command = CommandKeybind::CompositeKeybind(subkeymap); - keymaps.insert(Keycode::LOWER_P as i32, command); + keymaps.insert('p' as i32, command); } { let mut subkeymap: HashMap<i32, CommandKeybind> = HashMap::new(); let command = CommandKeybind::SimpleKeybind( Box::new(command::NewDirectory::new())); - subkeymap.insert(Keycode::LOWER_K as i32, command); + subkeymap.insert('k' as i32, command); let command = CommandKeybind::CompositeKeybind(subkeymap); - keymaps.insert(Keycode::LOWER_M as i32, command); + keymaps.insert('m' as i32, command); } JoshutoKeymap { @@ -165,21 +169,74 @@ impl JoshutoKeymap { } } + pub fn from_str(keycode: &str) -> Option<i32> + { + if keycode.len() == 1 { + for ch in keycode.chars() { + if ch.is_ascii() { + return Some(ch as i32); + } + } + return None; + } else { + match keycode { + "Comma" => Some(',' as i32), + "Tab" => Some(TAB), + "Space" => Some(' ' as i32), + "Backspace" => Some(BACKSPACE), + "Delete" => Some(ncurses::KEY_DC), + "Enter" => Some(ENTER), + "Escape" => Some(ESCAPE), + + + "F0" => Some(ncurses::KEY_F0), + "F1" => Some(ncurses::KEY_F1), + "F2" => Some(ncurses::KEY_F2), + "F3" => Some(ncurses::KEY_F3), + "F4" => Some(ncurses::KEY_F4), + "F5" => Some(ncurses::KEY_F5), + "F6" => Some(ncurses::KEY_F6), + "F7" => Some(ncurses::KEY_F7), + "F8" => Some(ncurses::KEY_F8), + "F9" => Some(ncurses::KEY_F9), + "F10" => Some(ncurses::KEY_F10), + "F11" => Some(ncurses::KEY_F11), + "F12" => Some(ncurses::KEY_F12), + "F13" => Some(ncurses::KEY_F13), + "F14" => Some(ncurses::KEY_F14), + "F15" => Some(ncurses::KEY_F15), + + "Insert" => Some(ncurses::KEY_IC), /* insert-character key */ + "PageUp" => Some(ncurses::KEY_PPAGE), /* next-page key */ + "PageDown" => Some(ncurses::KEY_NPAGE), /* previous-page key */ + "PrintScreen" => Some(ncurses::KEY_PRINT), /* print key */ + + "Up" => Some(ncurses::KEY_UP), + "Down" => Some(ncurses::KEY_DOWN), + "Left" => Some(ncurses::KEY_LEFT), + "Right" => Some(ncurses::KEY_RIGHT), + "Home" => Some(ncurses::KEY_HOME), + "End" => Some(ncurses::KEY_END), + _ => None, + } + } + } + fn insert_keycommand(map: &mut HashMap<i32, CommandKeybind>, keycommand: Box<dyn JoshutoCommand>, keys: &[&str]) { if keys.len() == 1 { - match Keycode::from_str(keys[0]) { + match Self::from_str(keys[0]) { Some(s) => { - map.insert(s as i32, CommandKeybind::SimpleKeybind(keycommand)); + map.insert(s, CommandKeybind::SimpleKeybind(keycommand)); }, None => {} } } else { - match Keycode::from_str(keys[0]) { + match Self::from_str(keys[0]) { Some(s) => { let mut new_map: HashMap<i32, CommandKeybind>; - match map.remove(&(s.clone() as i32)) { + match map.remove(&s) { Some(CommandKeybind::CompositeKeybind(mut m)) => { new_map = m; }, @@ -278,4 +335,3 @@ impl JoshutoKeymap { } } } - diff --git a/src/joshuto/keymapll.rs b/src/joshuto/keymapll.rs deleted file mode 100644 index c5ac77d..0000000 --- a/src/joshuto/keymapll.rs +++ /dev/null @@ -1,384 +0,0 @@ -extern crate ncurses; - -#[allow(non_camel_case_types)] -#[allow(dead_code)] -#[derive(Debug,Clone)] -pub enum Keycode { - CTRL = ncurses::BUTTON_CTRL as isize, - SHIFT = ncurses::BUTTON_SHIFT as isize, - ALT = ncurses::BUTTON_ALT as isize, - - A1 = ncurses::KEY_A1 as isize, - A3 = ncurses::KEY_A3 as isize, - B2 = ncurses::KEY_B2 as isize, - BEG = ncurses::KEY_BEG as isize, - BREAK = ncurses::KEY_BREAK as isize, - BTAB = ncurses::KEY_BTAB as isize, - C1 = ncurses::KEY_C1 as isize, - C3 = ncurses::KEY_C3 as isize, - CANCEL = ncurses::KEY_CANCEL as isize, - CATAB = ncurses::KEY_CATAB as isize, - CLEAR = ncurses::KEY_CLEAR as isize, - CLOSE = ncurses::KEY_CLOSE as isize, - CODE_YES = ncurses::KEY_CODE_YES as isize, - COMMAND = ncurses::KEY_COMMAND as isize, - COPY = ncurses::KEY_COPY as isize, - CREATE = ncurses::KEY_CREATE as isize, - CTAB = ncurses::KEY_CTAB as isize, - DELETE = ncurses::KEY_DC as isize, /* delete-character key */ - DL = ncurses::KEY_DL as isize, /* delete-line key */ - EIC = ncurses::KEY_EIC as isize, - EOL = ncurses::KEY_EOL as isize, - EOS = ncurses::KEY_EOS as isize, - EVENT = ncurses::KEY_EVENT as isize, - EXIT = ncurses::KEY_EXIT as isize, - F0 = ncurses::KEY_F0 as isize, - F10 = ncurses::KEY_F10 as isize, - F11 = ncurses::KEY_F11 as isize, - F12 = ncurses::KEY_F12 as isize, - F13 = ncurses::KEY_F13 as isize, - F14 = ncurses::KEY_F14 as isize, - F15 = ncurses::KEY_F15 as isize, - F1 = ncurses::KEY_F1 as isize, - F2 = ncurses::KEY_F2 as isize, - F3 = ncurses::KEY_F3 as isize, - F4 = ncurses::KEY_F4 as isize, - F5 = ncurses::KEY_F5 as isize, - F6 = ncurses::KEY_F6 as isize, - F7 = ncurses::KEY_F7 as isize, - F8 = ncurses::KEY_F8 as isize, - F9 = ncurses::KEY_F9 as isize, - FIND = ncurses::KEY_FIND as isize, - HELP = ncurses::KEY_HELP as isize, - - IC = ncurses::KEY_IC as isize, /* insert-character key */ - IL = ncurses::KEY_IL as isize, /* insert-line key */ - LL = ncurses::KEY_LL as isize, - MARK = ncurses::KEY_MARK as isize, - MAX = ncurses::KEY_MAX as isize, - MESSAGE = ncurses::KEY_MESSAGE as isize, - MOUSE = ncurses::KEY_MOUSE as isize, - MOVE = ncurses::KEY_MOVE as isize, - NEXT = ncurses::KEY_NEXT as isize, - NPAGE = ncurses::KEY_NPAGE as isize, /* next-page key */ - OPEN = ncurses::KEY_OPEN as isize, - OPTIONS = ncurses::KEY_OPTIONS as isize, - PPAGE = ncurses::KEY_PPAGE as isize, /* previous-page key */ - PREVIOUS = ncurses::KEY_PREVIOUS as isize, - PRINT = ncurses::KEY_PRINT as isize, /* print key */ - REDO = ncurses::KEY_REDO as isize, - REFERENCE = ncurses::KEY_REFERENCE as isize, - REFRESH = ncurses::KEY_REFRESH as isize, - REPLACE = ncurses::KEY_REPLACE as isize, - RESET = ncurses::KEY_RESET as isize, - RESIZE = ncurses::KEY_RESIZE as isize, - RESTART = ncurses::KEY_RESTART as isize, - RESUME = ncurses::KEY_RESUME as isize, - SAVE = ncurses::KEY_SAVE as isize, - SBEG = ncurses::KEY_SBEG as isize, - SCANCEL = ncurses::KEY_SCANCEL as isize, - SCOMMAND = ncurses::KEY_SCOMMAND as isize, - SCOPY = ncurses::KEY_SCOPY as isize, - SCREATE = ncurses::KEY_SCREATE as isize, - SDC = ncurses::KEY_SDC as isize, - SDL = ncurses::KEY_SDL as isize, - SELECT = ncurses::KEY_SELECT as isize, - SEND = ncurses::KEY_SEND as isize, - SEOL = ncurses::KEY_SEOL as isize, - SEXIT = ncurses::KEY_SEXIT as isize, - SFIND = ncurses::KEY_SFIND as isize, - SF = ncurses::KEY_SF as isize, - SHELP = ncurses::KEY_SHELP as isize, - SHOME = ncurses::KEY_SHOME as isize, - SIC = ncurses::KEY_SIC as isize, - SLEFT = ncurses::KEY_SLEFT as isize, - SMESSAGE = ncurses::KEY_SMESSAGE as isize, - SMOVE = ncurses::KEY_SMOVE as isize, - SNEXT = ncurses::KEY_SNEXT as isize, - SOPTIONS = ncurses::KEY_SOPTIONS as isize, - SPREVIOUS = ncurses::KEY_SPREVIOUS as isize, - SPRINT = ncurses::KEY_SPRINT as isize, - SREDO = ncurses::KEY_SREDO as isize, - SREPLACE = ncurses::KEY_SREPLACE as isize, - SRESET = ncurses::KEY_SRESET as isize, - SRIGHT = ncurses::KEY_SRIGHT as isize, - SR = ncurses::KEY_SR as isize, - SRSUME = ncurses::KEY_SRSUME as isize, - SSAVE = ncurses::KEY_SSAVE as isize, - SSUSPEND = ncurses::KEY_SSUSPEND as isize, - STAB = ncurses::KEY_STAB as isize, - SUNDO = ncurses::KEY_SUNDO as isize, - SUSPEND = ncurses::KEY_SUSPEND as isize, - UNDO = ncurses::KEY_UNDO as isize, - - UP = ncurses::KEY_UP as isize, - DOWN = ncurses::KEY_DOWN as isize, - LEFT = ncurses::KEY_LEFT as isize, - RIGHT = ncurses::KEY_RIGHT as isize, - HOME = ncurses::KEY_HOME as isize, - END = ncurses::KEY_END as isize, - - BACKSPACE = 0x7F, - SPACE = 0x20, - TAB = 0x9, - ENTER = 0xA, - ESCAPE = 0x1B, - - ZERO = 0x30, - ONE = 0x31, - TWO = 0x32, - THREE = 0x33, - FOUR = 0x34, - FIVE = 0x35, - SIX = 0x36, - SEVEN = 0x37, - EIGHT = 0x38, - NINE = 0x39, - - UPPER_A = 0x41, - UPPER_B = 0x42, - UPPER_C = 0x43, - UPPER_D = 0x44, - UPPER_E = 0x45, - UPPER_F = 0x46, - UPPER_G = 0x47, - UPPER_H = 0x48, - UPPER_I = 0x49, - UPPER_J = 0x4A, - UPPER_K = 0x4B, - UPPER_L = 0x4C, - UPPER_M = 0x4D, - UPPER_N = 0x4E, - UPPER_O = 0x4F, - UPPER_P = 0x50, - UPPER_Q = 0x51, - UPPER_R = 0x52, - UPPER_S = 0x53, - UPPER_T = 0x54, - UPPER_U = 0x55, - UPPER_V = 0x56, - UPPER_W = 0x57, - UPPER_X = 0x58, - UPPER_Y = 0x59, - UPPER_Z = 0x5A, - - LOWER_A = 0x61, - LOWER_B = 0x62, - LOWER_C = 0x63, - LOWER_D = 0x64, - LOWER_E = 0x65, - LOWER_F = 0x66, - LOWER_G = 0x67, - LOWER_H = 0x68, - LOWER_I = 0x69, - LOWER_J = 0x6A, - LOWER_K = 0x6B, - LOWER_L = 0x6C, - LOWER_M = 0x6D, - LOWER_N = 0x6E, - LOWER_O = 0x6F, - LOWER_P = 0x70, - LOWER_Q = 0x71, - LOWER_R = 0x72, - LOWER_S = 0x73, - LOWER_T = 0x74, - LOWER_U = 0x75, - LOWER_V = 0x76, - LOWER_W = 0x77, - LOWER_X = 0x78, - LOWER_Y = 0x79, - LOWER_Z = 0x7A, -} - -impl Keycode { - pub fn from_str(keycode: &str) -> Option<Keycode> - { - match keycode { - "0" => Some(Keycode::ZERO), - "1" => Some(Keycode::ONE), - "2" => Some(Keycode::TWO), - "3" => Some(Keycode::THREE), - "4" => Some(Keycode::FOUR), - "5" => Some(Keycode::FIVE), - "6" => Some(Keycode::SIX), - "7" => Some(Keycode::SEVEN), - "8" => Some(Keycode::EIGHT), - "9" => Some(Keycode::NINE), - - "A" => Some(Keycode::UPPER_A), - "B" => Some(Keycode::UPPER_B), - "C" => Some(Keycode::UPPER_C), - "D" => Some(Keycode::UPPER_D), - "E" => Some(Keycode::UPPER_E), - "F" => Some(Keycode::UPPER_F), - "G" => Some(Keycode::UPPER_G), - "H" => Some(Keycode::UPPER_H), - "I" => Some(Keycode::UPPER_I), - "J" => Some(Keycode::UPPER_J), - "K" => Some(Keycode::UPPER_K), - "L" => Some(Keycode::UPPER_L), - "M" => Some(Keycode::UPPER_M), - "N" => Some(Keycode::UPPER_N), - "O" => Some(Keycode::UPPER_O), - "P" => Some(Keycode::UPPER_P), - "Q" => Some(Keycode::UPPER_Q), - "R" => Some(Keycode::UPPER_R), - "S" => Some(Keycode::UPPER_S), - "T" => Some(Keycode::UPPER_T), - "U" => Some(Keycode::UPPER_U), - "V" => Some(Keycode::UPPER_V), - "W" => Some(Keycode::UPPER_W), - "X" => Some(Keycode::UPPER_X), - "Y" => Some(Keycode::UPPER_Y), - "Z" => Some(Keycode::UPPER_Z), - - "a" => Some(Keycode::LOWER_A), - "b" => Some(Keycode::LOWER_B), - "c" => Some(Keycode::LOWER_C), - "d" => Some(Keycode::LOWER_D), - "e" => Some(Keycode::LOWER_E), - "f" => Some(Keycode::LOWER_F), - "g" => Some(Keycode::LOWER_G), - "h" => Some(Keycode::LOWER_H), - "i" => Some(Keycode::LOWER_I), - "j" => Some(Keycode::LOWER_J), - "k" => Some(Keycode::LOWER_K), - "l" => Some(Keycode::LOWER_L), - "m" => Some(Keycode::LOWER_M), - "n" => Some(Keycode::LOWER_N), - "o" => Some(Keycode::LOWER_O), - "p" => Some(Keycode::LOWER_P), - "q" => Some(Keycode::LOWER_Q), - "r" => Some(Keycode::LOWER_R), - "s" => Some(Keycode::LOWER_S), - "t" => Some(Keycode::LOWER_T), - "u" => Some(Keycode::LOWER_U), - "v" => Some(Keycode::LOWER_V), - "w" => Some(Keycode::LOWER_W), - "x" => Some(Keycode::LOWER_X), - "y" => Some(Keycode::LOWER_Y), - "z" => Some(Keycode::LOWER_Z), - - "CTRL" => Some(Keycode::CTRL), - "SHIFT" => Some(Keycode::SHIFT), - "ALT" => Some(Keycode::ALT), - - "SPACE" => Some(Keycode::SPACE), - - "A1" => Some(Keycode::A1), - "A3" => Some(Keycode::A3), - "B2" => Some(Keycode::B2), - "BACKSPACE" => Some(Keycode::BACKSPACE), - "BEG" => Some(Keycode::BEG), - "BREAK" => Some(Keycode::BREAK), - "BTAB" => Some(Keycode::BTAB), - "C1" => Some(Keycode::C1), - "C3" => Some(Keycode::C3), - "CANCEL" => Some(Keycode::CANCEL), - "CATAB" => Some(Keycode::CATAB), - "CLEAR" => Some(Keycode::CLEAR), - "CLOSE" => Some(Keycode::CLOSE), - "CODE_YES" => Some(Keycode::CODE_YES), - "COMMAND" => Some(Keycode::COMMAND), - "COPY" => Some(Keycode::COPY), - "CREATE" => Some(Keycode::CREATE), - "CTAB" => Some(Keycode::CTAB), - "DELETE" => Some(Keycode::DELETE), - "DL" => Some(Keycode::DL), - "DOWN" => Some(Keycode::DOWN), - "EIC" => Some(Keycode::EIC), - "END" => Some(Keycode::END), - - "ENTER" => Some(Keycode::ENTER), - "EOL" => Some(Keycode::EOL), - "EOS" => Some(Keycode::EOS), - "EVENT" => Some(Keycode::EVENT), - "EXIT" => Some(Keycode::EXIT), - "F0" => Some(Keycode::F0), - "F10" => Some(Keycode::F10), - "F11" => Some(Keycode::F11), - "F12" => Some(Keycode::F12), - "F13" => Some(Keycode::F13), - "F14" => Some(Keycode::F14), - "F15" => Some(Keycode::F15), - "F1" => Some(Keycode::F1), - "F2" => Some(Keycode::F2), - "F3" => Some(Keycode::F3), - "F4" => Some(Keycode::F4), - "F5" => Some(Keycode::F5), - "F6" => Some(Keycode::F6), - "F7" => Some(Keycode::F7), - "F8" => Some(Keycode::F8), - "F9" => Some(Keycode::F9), - "FIND" => Some(Keycode::FIND), - "HELP" => Some(Keycode::HELP), - "HOME" => Some(Keycode::HOME), - "IL" => Some(Keycode::IL), - "INSERT" => Some(Keycode::IC), - "LEFT" => Some(Keycode::LEFT), - "LL" => Some(Keycode::LL), - "MARK" => Some(Keycode::MARK), - "MAX" => Some(Keycode::MAX), - "MESSAGE" => Some(Keycode::MESSAGE), - "MOUSE" => Some(Keycode::MOUSE), - "MOVE" => Some(Keycode::MOVE), - "NEXT" => Some(Keycode::NEXT), - "NPAGE" => Some(Keycode::NPAGE), - "OPEN" => Some(Keycode::OPEN), - "OPTIONS" => Some(Keycode::OPTIONS), - "PPAGE" => Some(Keycode::PPAGE), - "PREVIOUS" => Some(Keycode::PREVIOUS), - "PRINT" => Some(Keycode::PRINT), - "REDO" => Some(Keycode::REDO), - "REFERENCE" => Some(Keycode::REFERENCE), - "REFRESH" => Some(Keycode::REFRESH), - "REPLACE" => Some(Keycode::REPLACE), - "RESET" => Some(Keycode::RESET), - "RESIZE" => Some(Keycode::RESIZE), - "RESTART" => Some(Keycode::RESTART), - "RESUME" => Some(Keycode::RESUME), - "RIGHT" => Some(Keycode::RIGHT), - "SAVE" => Some(Keycode::SAVE), - "SBEG" => Some(Keycode::SBEG), - "SCANCEL" => Some(Keycode::SCANCEL), - "SCOMMAND" => Some(Keycode::SCOMMAND), - "SCOPY" => Some(Keycode::SCOPY), - "SCREATE" => Some(Keycode::SCREATE), - "SDC" => Some(Keycode::SDC), - "SDL" => Some(Keycode::SDL), - "SELECT" => Some(Keycode::SELECT), - "SEND" => Some(Keycode::SEND), - "SEOL" => Some(Keycode::SEOL), - "SEXIT" => Some(Keycode::SEXIT), - "SFIND" => Some(Keycode::SFIND), - "SF" => Some(Keycode::SF), - "SHELP" => Some(Keycode::SHELP), - "SHOME" => Some(Keycode::SHOME), - "SIC" => Some(Keycode::SIC), - "SLEFT" => Some(Keycode::SLEFT), - "SMESSAGE" => Some(Keycode::SMESSAGE), - |