blob: cdf47e25f1a8b3b106d09e8d6e35b56e4d882c3a (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// bibiman - a TUI for managing BibLaTeX databases
// Copyright (C) 2024 lukeflo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/////
use crate::frontend::app::{App, AppResult};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use super::app::CurrentArea;
/// Handles the key events and updates the state of [`App`].
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
// Keycodes activated for every area (high priority)
match key_event.code {
// Exit application on `ESC` or `q`
KeyCode::Esc | KeyCode::Char('q') => {
app.quit();
}
// Exit application on `Ctrl-C`
KeyCode::Char('c') | KeyCode::Char('C') => {
if key_event.modifiers == KeyModifiers::CONTROL {
app.quit();
}
}
_ => {}
}
// Keycodes for specific areas
match app.current_area {
// Keycodes for the tag area
CurrentArea::TagArea => match key_event.code {
KeyCode::Char('j') | KeyCode::Down => {
app.select_next();
}
KeyCode::Char('k') | KeyCode::Up => {
app.select_previous();
}
KeyCode::Char('h') | KeyCode::Left => {
app.select_none();
}
KeyCode::Char('g') | KeyCode::Home => {
app.select_first();
}
KeyCode::Char('G') | KeyCode::End => {
app.select_last();
}
KeyCode::Tab | KeyCode::BackTab => {
app.toggle_area();
}
_ => {}
},
// Keycodes for the entry area
CurrentArea::EntryArea => match key_event.code {
KeyCode::Char('j') | KeyCode::Down => {
app.select_next();
}
KeyCode::Char('k') | KeyCode::Up => {
app.select_previous();
}
KeyCode::Char('h') | KeyCode::Left => {
app.select_none();
}
KeyCode::Char('g') | KeyCode::Home => {
app.select_first();
}
KeyCode::Char('G') | KeyCode::End => {
app.select_last();
}
KeyCode::Tab | KeyCode::BackTab => {
app.toggle_area();
}
_ => {}
},
}
Ok(())
}
|