blob: e99e2e00217ba8b6c95a74685cc35845c3c26261 (
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
|
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
use ratatui::prelude::*;
use ratatui::widgets::*;
use crate::app_action::AppAction;
use crate::component::Component;
#[derive(Default, Clone, Copy)]
pub struct GlobalKeys {
should_show: bool,
}
impl Component for GlobalKeys {
fn handle_key_event(
&mut self,
key: KeyEvent,
) -> eyre::Result<Option<AppAction>> {
if key.kind == KeyEventKind::Press {
return match key.code {
KeyCode::Char('q') => Ok(Some(AppAction::Quit)),
KeyCode::Char('?') => {
self.should_show = !self.should_show;
Ok(None)
}
_ => Ok(None),
};
}
Ok(None)
}
fn render(&mut self, frame: &mut Frame, rect: Rect) -> eyre::Result<()> {
let horizontal_center = Layout::default()
.direction(Direction::Horizontal);
let block = Block::default()
.title("Keyboard shortcuts")
.borders(Borders::ALL);
if self.should_show {
frame.render_widget(block, rect);
}
Ok(())
}
}
|