-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
input.rs
55 lines (51 loc) · 1.19 KB
/
input.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// TODO(eliza): support Ratatui backends other than crossterm?
// This would probably involve using `spawn_blocking` to drive their blocking
// input-handling mechanisms in the background...
pub use crossterm::event::*;
pub fn should_quit(input: &Event) -> bool {
use Event::*;
use KeyCode::*;
match input {
Key(KeyEvent {
code: Char('q'), ..
}) => true,
Key(KeyEvent {
code: Char('c'),
modifiers,
..
})
| Key(KeyEvent {
code: Char('d'),
modifiers,
..
}) if modifiers.contains(KeyModifiers::CONTROL) => true,
_ => false,
}
}
pub(crate) fn is_space(input: &Event) -> bool {
matches!(
input,
Event::Key(KeyEvent {
code: KeyCode::Char(' '),
..
})
)
}
pub(crate) fn is_help_toggle(event: &Event) -> bool {
matches!(
event,
Event::Key(KeyEvent {
code: KeyCode::Char('?'),
..
})
)
}
pub(crate) fn is_esc(event: &Event) -> bool {
matches!(
event,
Event::Key(KeyEvent {
code: KeyCode::Esc,
..
})
)
}