use crate::key;
use crossterm::event::KeyCode;
#[derive(Debug, Clone)]
pub struct ListKeyMap {
pub cursor_up: key::Binding,
pub cursor_down: key::Binding,
pub next_page: key::Binding,
pub prev_page: key::Binding,
pub go_to_start: key::Binding,
pub go_to_end: key::Binding,
pub filter: key::Binding,
pub clear_filter: key::Binding,
pub cancel_filter: key::Binding,
pub accept_filter: key::Binding,
pub show_full_help: key::Binding,
pub close_full_help: key::Binding,
pub quit: key::Binding,
pub force_quit: key::Binding,
}
impl Default for ListKeyMap {
fn default() -> Self {
Self {
cursor_up: key::Binding::new(vec![KeyCode::Up, KeyCode::Char('k')])
.with_help("↑/k", "up"),
cursor_down: key::Binding::new(vec![KeyCode::Down, KeyCode::Char('j')])
.with_help("↓/j", "down"),
next_page: key::Binding::new(vec![
KeyCode::Right,
KeyCode::Char('l'),
KeyCode::PageDown,
KeyCode::Char('f'),
KeyCode::Char('d'),
])
.with_help("→/l/pgdn", "next page"),
prev_page: key::Binding::new(vec![
KeyCode::Left,
KeyCode::Char('h'),
KeyCode::PageUp,
KeyCode::Char('b'),
KeyCode::Char('u'),
])
.with_help("←/h/pgup", "prev page"),
go_to_start: key::Binding::new(vec![KeyCode::Home, KeyCode::Char('g')])
.with_help("g/home", "go to start"),
go_to_end: key::Binding::new(vec![KeyCode::End, KeyCode::Char('G')])
.with_help("G/end", "go to end"),
filter: key::Binding::new(vec![KeyCode::Char('/')]).with_help("/", "filter"),
clear_filter: key::Binding::new(vec![KeyCode::Esc]).with_help("esc", "clear filter"),
cancel_filter: key::Binding::new(vec![KeyCode::Esc]).with_help("esc", "cancel"),
accept_filter: key::Binding::new(vec![
KeyCode::Enter,
KeyCode::Tab,
KeyCode::Up,
KeyCode::Down,
])
.with_help("enter", "apply filter"),
show_full_help: key::Binding::new(vec![KeyCode::Char('?')]).with_help("?", "more"),
close_full_help: key::Binding::new(vec![KeyCode::Char('?')])
.with_help("?", "close help"),
quit: key::Binding::new(vec![KeyCode::Char('q'), KeyCode::Esc]).with_help("q", "quit"),
force_quit: key::new_binding(vec![key::with_keys_str(&["ctrl+c"])])
.with_help("ctrl+c", "force quit"),
}
}
}
impl key::KeyMap for ListKeyMap {
fn short_help(&self) -> Vec<&key::Binding> {
vec![&self.cursor_up, &self.cursor_down, &self.filter, &self.quit]
}
fn full_help(&self) -> Vec<Vec<&key::Binding>> {
vec![
vec![
&self.cursor_up,
&self.cursor_down,
&self.next_page,
&self.prev_page,
&self.go_to_start,
&self.go_to_end,
],
vec![
&self.filter,
&self.clear_filter,
&self.accept_filter,
&self.cancel_filter,
],
vec![&self.show_full_help, &self.quit],
]
}
}