diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-09-25 12:59:08 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-09-25 12:59:08 -0400 |
commit | cbfdb2c715f47944e10b4a74e8fc74c1b51977de (patch) | |
tree | d56751a4888ff2162f2dbebbe5e5938c51f33ca4 /src/config | |
parent | 281da8fcc27563530289046838bb50d340fa33ce (diff) |
show_workers can close with custom key via --exit-key option
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/keymap/keymapping.rs | 2 | ||||
-rw-r--r-- | src/config/keymap/keyparse.rs | 82 | ||||
-rw-r--r-- | src/config/keymap/mod.rs | 2 |
3 files changed, 1 insertions, 85 deletions
diff --git a/src/config/keymap/keymapping.rs b/src/config/keymap/keymapping.rs index e102f9c..e36e49a 100644 --- a/src/config/keymap/keymapping.rs +++ b/src/config/keymap/keymapping.rs @@ -7,7 +7,7 @@ use std::str::FromStr; use termion::event::MouseEvent; use termion::event::{Event, Key}; -use super::keyparse::str_to_event; +use crate::util::keyparse::str_to_event; use crate::commands::{CommandKeybind, KeyCommand}; use crate::config::{parse_to_config_file, ConfigStructure, Flattenable}; use crate::io::IoWorkerOptions; diff --git a/src/config/keymap/keyparse.rs b/src/config/keymap/keyparse.rs deleted file mode 100644 index e850cc2..0000000 --- a/src/config/keymap/keyparse.rs +++ /dev/null @@ -1,82 +0,0 @@ -use termion::event::{Event, Key, MouseButton, MouseEvent}; - -pub fn str_to_event(s: &str) -> Option<Event> { - if let Some(k) = str_to_key(s) { - Some(Event::Key(k)) - } else if let Some(m) = str_to_mouse(s) { - Some(Event::Mouse(m)) - } else { - None - } -} - -pub fn str_to_key(s: &str) -> Option<Key> { - if s.is_empty() { - return None; - } - - let key = match s { - "backspace" => Some(Key::Backspace), - "backtab" => Some(Key::BackTab), - "arrow_left" => Some(Key::Left), - "arrow_right" => Some(Key::Right), - "arrow_up" => Some(Key::Up), - "arrow_down" => Some(Key::Down), - "home" => Some(Key::Home), - "end" => Some(Key::End), - "page_up" => Some(Key::PageUp), - "page_down" => Some(Key::PageDown), - "delete" => Some(Key::Delete), - "insert" => Some(Key::Insert), - "escape" => Some(Key::Esc), - "f1" => Some(Key::F(1)), - "f2" => Some(Key::F(2)), - "f3" => Some(Key::F(3)), - "f4" => Some(Key::F(4)), - "f5" => Some(Key::F(5)), - "f6" => Some(Key::F(6)), - "f7" => Some(Key::F(7)), - "f8" => Some(Key::F(8)), - "f9" => Some(Key::F(9)), - "f10" => Some(Key::F(10)), - "f11" => Some(Key::F(11)), - "f12" => Some(Key::F(12)), - _ => None, - }; - - if key.is_some() { - return key; - } - - if s.starts_with("ctrl+") { - let ch = s.chars().nth("ctrl+".len()); - let key = match ch { - Some(ch) => Some(Key::Ctrl(ch)), - None => None, - }; - return key; - } else if s.starts_with("alt+") { - let ch = s.chars().nth("alt+".len()); - let key = match ch { - Some(ch) => Some(Key::Alt(ch)), - None => None, - }; - return key; - } else if s.len() == 1 { - let ch = s.chars().next(); - let key = match ch { - Some(ch) => Some(Key::Char(ch)), - None => None, - }; - return key; - } - None -} - -pub fn str_to_mouse(s: &str) -> Option<MouseEvent> { - match s { - "scroll_up" => Some(MouseEvent::Press(MouseButton::WheelUp, 0, 0)), - "scroll_down" => Some(MouseEvent::Press(MouseButton::WheelDown, 0, 0)), - _ => None, - } -} diff --git a/src/config/keymap/mod.rs b/src/config/keymap/mod.rs index a224626..14ad630 100644 --- a/src/config/keymap/mod.rs +++ b/src/config/keymap/mod.rs @@ -1,5 +1,3 @@ -pub mod keyparse; - mod keymapping; pub use self::keymapping::AppKeyMapping; |