bubbletea_widgets/list/
keys.rs1use crate::key;
37use crossterm::event::KeyCode;
38
39#[derive(Debug, Clone)]
41pub struct ListKeyMap {
42 pub cursor_up: key::Binding,
44 pub cursor_down: key::Binding,
46 pub next_page: key::Binding,
48 pub prev_page: key::Binding,
50 pub go_to_start: key::Binding,
52 pub go_to_end: key::Binding,
54 pub filter: key::Binding,
56 pub clear_filter: key::Binding,
58 pub cancel_filter: key::Binding,
60 pub accept_filter: key::Binding,
62 pub show_full_help: key::Binding,
64 pub close_full_help: key::Binding,
66 pub quit: key::Binding,
68 pub force_quit: key::Binding,
70}
71
72impl Default for ListKeyMap {
73 fn default() -> Self {
74 Self {
75 cursor_up: key::Binding::new(vec![KeyCode::Up, KeyCode::Char('k')])
76 .with_help("↑/k", "up"),
77 cursor_down: key::Binding::new(vec![KeyCode::Down, KeyCode::Char('j')])
78 .with_help("↓/j", "down"),
79 next_page: key::Binding::new(vec![
80 KeyCode::Right,
81 KeyCode::Char('l'),
82 KeyCode::PageDown,
83 KeyCode::Char('f'),
84 KeyCode::Char('d'),
85 ])
86 .with_help("→/l/pgdn", "next page"),
87 prev_page: key::Binding::new(vec![
88 KeyCode::Left,
89 KeyCode::Char('h'),
90 KeyCode::PageUp,
91 KeyCode::Char('b'),
92 KeyCode::Char('u'),
93 ])
94 .with_help("←/h/pgup", "prev page"),
95 go_to_start: key::Binding::new(vec![KeyCode::Home, KeyCode::Char('g')])
96 .with_help("g/home", "go to start"),
97 go_to_end: key::Binding::new(vec![KeyCode::End, KeyCode::Char('G')])
98 .with_help("G/end", "go to end"),
99 filter: key::Binding::new(vec![KeyCode::Char('/')]).with_help("/", "filter"),
100 clear_filter: key::Binding::new(vec![KeyCode::Esc]).with_help("esc", "clear filter"),
101 cancel_filter: key::Binding::new(vec![KeyCode::Esc]).with_help("esc", "cancel"),
102 accept_filter: key::Binding::new(vec![
104 KeyCode::Enter,
105 KeyCode::Tab,
106 KeyCode::Up,
107 KeyCode::Down,
108 ])
109 .with_help("enter", "apply filter"),
110 show_full_help: key::Binding::new(vec![KeyCode::Char('?')]).with_help("?", "more"),
111 close_full_help: key::Binding::new(vec![KeyCode::Char('?')])
112 .with_help("?", "close help"),
113 quit: key::Binding::new(vec![KeyCode::Char('q'), KeyCode::Esc]).with_help("q", "quit"),
114 force_quit: key::new_binding(vec![key::with_keys_str(&["ctrl+c"])])
116 .with_help("ctrl+c", "force quit"),
117 }
118 }
119}
120
121impl key::KeyMap for ListKeyMap {
122 fn short_help(&self) -> Vec<&key::Binding> {
123 vec![&self.cursor_up, &self.cursor_down, &self.filter, &self.quit]
124 }
125
126 fn full_help(&self) -> Vec<Vec<&key::Binding>> {
127 vec![
128 vec![&self.cursor_up, &self.cursor_down],
129 vec![&self.next_page, &self.prev_page],
130 vec![&self.go_to_start, &self.go_to_end],
131 vec![&self.filter, &self.clear_filter, &self.accept_filter],
132 vec![&self.show_full_help, &self.quit],
133 ]
134 }
135}