blob: 3e8fd8d94a551b13d3c59f83fbabae902d844a0f (
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
|
use crossterm::event::{KeyEvent, MouseEvent};
use eyre::Result;
use ratatui::prelude::{Frame, Rect};
use crate::app_action::AppAction;
use crate::app_event::AppEvent;
pub trait Component {
fn init(&mut self) -> Result<()> {
Ok(())
}
#[allow(unused)]
fn handle_action(&mut self, action: AppAction) {}
#[allow(unused)]
fn handle_event(&mut self, event: AppEvent) -> Option<AppAction> {
match event {
AppEvent::Key(key_event) => self.handle_key_event(key_event),
AppEvent::Mouse(mouse_event) => {
self.handle_mouse_event(mouse_event)
}
_ => None,
}
}
#[allow(unused)]
fn handle_key_event(&mut self, key: KeyEvent) -> Option<AppAction> {
None
}
#[allow(unused)]
fn handle_mouse_event(&mut self, mouse: MouseEvent) -> Option<AppAction> {
None
}
#[allow(unused)]
fn update(&mut self) -> Option<AppEvent> {
None
}
fn render(&mut self, frame: &mut Frame, rect: Rect) -> Result<()>;
}
|