feat: Support alternative keymappings for all keys, featuring hjkl movements
This commit is contained in:
+61
-1
@@ -44,128 +44,188 @@ generate_keybindings! {
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
||||
pub struct KeyBinding {
|
||||
pub key: Key,
|
||||
pub alt: Option<Key>,
|
||||
pub desc: &'static str,
|
||||
}
|
||||
|
||||
pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings {
|
||||
add: KeyBinding {
|
||||
key: Key::Char('a'),
|
||||
alt: None,
|
||||
desc: "add",
|
||||
},
|
||||
up: KeyBinding {
|
||||
key: Key::Up,
|
||||
alt: Some(Key::Char('k')),
|
||||
desc: "up",
|
||||
},
|
||||
down: KeyBinding {
|
||||
key: Key::Down,
|
||||
alt: Some(Key::Char('j')),
|
||||
desc: "down",
|
||||
},
|
||||
left: KeyBinding {
|
||||
key: Key::Left,
|
||||
alt: Some(Key::Char('h')),
|
||||
desc: "left",
|
||||
},
|
||||
right: KeyBinding {
|
||||
key: Key::Right,
|
||||
alt: Some(Key::Char('l')),
|
||||
desc: "right",
|
||||
},
|
||||
backspace: KeyBinding {
|
||||
key: Key::Backspace,
|
||||
alt: None,
|
||||
desc: "backspace",
|
||||
},
|
||||
next_servarr: KeyBinding {
|
||||
key: Key::Tab,
|
||||
alt: None,
|
||||
desc: "next servarr",
|
||||
},
|
||||
previous_servarr: KeyBinding {
|
||||
key: Key::BackTab,
|
||||
alt: None,
|
||||
desc: "previous servarr",
|
||||
},
|
||||
clear: KeyBinding {
|
||||
key: Key::Char('c'),
|
||||
alt: None,
|
||||
desc: "clear",
|
||||
},
|
||||
auto_search: KeyBinding {
|
||||
key: Key::Char('S'),
|
||||
alt: None,
|
||||
desc: "auto search",
|
||||
},
|
||||
search: KeyBinding {
|
||||
key: Key::Char('s'),
|
||||
alt: None,
|
||||
desc: "search",
|
||||
},
|
||||
settings: KeyBinding {
|
||||
key: Key::Char('S'),
|
||||
alt: None,
|
||||
desc: "settings",
|
||||
},
|
||||
filter: KeyBinding {
|
||||
key: Key::Char('f'),
|
||||
alt: None,
|
||||
desc: "filter",
|
||||
},
|
||||
sort: KeyBinding {
|
||||
key: Key::Char('o'),
|
||||
alt: None,
|
||||
desc: "sort",
|
||||
},
|
||||
edit: KeyBinding {
|
||||
key: Key::Char('e'),
|
||||
alt: None,
|
||||
desc: "edit",
|
||||
},
|
||||
events: KeyBinding {
|
||||
key: Key::Char('e'),
|
||||
alt: None,
|
||||
desc: "events",
|
||||
},
|
||||
logs: KeyBinding {
|
||||
key: Key::Char('l'),
|
||||
key: Key::Char('L'),
|
||||
alt: None,
|
||||
desc: "logs",
|
||||
},
|
||||
tasks: KeyBinding {
|
||||
key: Key::Char('t'),
|
||||
alt: None,
|
||||
desc: "tasks",
|
||||
},
|
||||
test: KeyBinding {
|
||||
key: Key::Char('t'),
|
||||
alt: None,
|
||||
desc: "test",
|
||||
},
|
||||
test_all: KeyBinding {
|
||||
key: Key::Char('T'),
|
||||
alt: None,
|
||||
desc: "test all",
|
||||
},
|
||||
toggle_monitoring: KeyBinding {
|
||||
key: Key::Char('m'),
|
||||
alt: None,
|
||||
desc: "toggle monitoring",
|
||||
},
|
||||
refresh: KeyBinding {
|
||||
key: Key::Ctrl('r'),
|
||||
alt: None,
|
||||
desc: "refresh",
|
||||
},
|
||||
update: KeyBinding {
|
||||
key: Key::Char('u'),
|
||||
alt: None,
|
||||
desc: "update",
|
||||
},
|
||||
home: KeyBinding {
|
||||
key: Key::Home,
|
||||
alt: None,
|
||||
desc: "home",
|
||||
},
|
||||
end: KeyBinding {
|
||||
key: Key::End,
|
||||
alt: None,
|
||||
desc: "end",
|
||||
},
|
||||
delete: KeyBinding {
|
||||
key: Key::Delete,
|
||||
alt: None,
|
||||
desc: "delete",
|
||||
},
|
||||
submit: KeyBinding {
|
||||
key: Key::Enter,
|
||||
alt: None,
|
||||
desc: "submit",
|
||||
},
|
||||
confirm: KeyBinding {
|
||||
key: Key::Ctrl('s'),
|
||||
alt: None,
|
||||
desc: "submit",
|
||||
},
|
||||
quit: KeyBinding {
|
||||
key: Key::Char('q'),
|
||||
alt: None,
|
||||
desc: "quit",
|
||||
},
|
||||
esc: KeyBinding {
|
||||
key: Key::Esc,
|
||||
alt: None,
|
||||
desc: "close",
|
||||
},
|
||||
};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! matches_key {
|
||||
($binding:ident, $key:expr) => {
|
||||
$crate::app::key_binding::DEFAULT_KEYBINDINGS.$binding.key == $key
|
||||
|| ($crate::app::key_binding::DEFAULT_KEYBINDINGS
|
||||
.$binding
|
||||
.alt
|
||||
.is_some()
|
||||
&& $crate::app::key_binding::DEFAULT_KEYBINDINGS
|
||||
.$binding
|
||||
.alt
|
||||
.unwrap()
|
||||
== $key)
|
||||
};
|
||||
($binding:ident, $key:expr, $ignore_alt_navigation:expr) => {
|
||||
$crate::app::key_binding::DEFAULT_KEYBINDINGS.$binding.key == $key
|
||||
|| !$ignore_alt_navigation
|
||||
&& ($crate::app::key_binding::DEFAULT_KEYBINDINGS
|
||||
.$binding
|
||||
.alt
|
||||
.is_some()
|
||||
&& $crate::app::key_binding::DEFAULT_KEYBINDINGS
|
||||
.$binding
|
||||
.alt
|
||||
.unwrap()
|
||||
== $key)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ mod test {
|
||||
#[case(DEFAULT_KEYBINDINGS.sort, Key::Char('o'), "sort")]
|
||||
#[case(DEFAULT_KEYBINDINGS.edit, Key::Char('e'), "edit")]
|
||||
#[case(DEFAULT_KEYBINDINGS.events, Key::Char('e'), "events")]
|
||||
#[case(DEFAULT_KEYBINDINGS.logs, Key::Char('l'), "logs")]
|
||||
#[case(DEFAULT_KEYBINDINGS.logs, Key::Char('L'), "logs")]
|
||||
#[case(DEFAULT_KEYBINDINGS.tasks, Key::Char('t'), "tasks")]
|
||||
#[case(DEFAULT_KEYBINDINGS.test, Key::Char('t'), "test")]
|
||||
#[case(DEFAULT_KEYBINDINGS.test_all, Key::Char('T'), "test all")]
|
||||
|
||||
Reference in New Issue
Block a user