systemctl_tui/components/
mod.rs1use anyhow::Result;
2use crossterm::event::{KeyEvent, MouseEvent};
3use ratatui::{layout::Rect, Frame};
4use tokio::sync::mpsc::UnboundedSender;
5
6use crate::{action::Action, event::Event};
7
8pub mod home;
9pub mod logger;
10
11pub trait Component {
12 #[allow(unused_variables)]
13 fn init(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
14 Ok(())
15 }
16 fn handle_events(&mut self, event: Option<Event>) -> Vec<Action> {
17 match event {
18 Some(Event::Quit) => vec![Action::Quit],
19 Some(Event::RenderTick) => vec![Action::Render],
20 Some(Event::Key(key_event)) => self.handle_key_events(key_event),
21 Some(Event::Mouse(mouse_event)) => self.handle_mouse_events(mouse_event),
22 Some(Event::Resize(x, y)) => vec![Action::Resize(x, y)],
23 Some(Event::RefreshTick) => vec![Action::RefreshServices],
24 Some(_) => vec![],
25 None => vec![],
26 }
27 }
28 #[allow(unused_variables)]
29 fn handle_key_events(&mut self, key: KeyEvent) -> Vec<Action> {
30 vec![]
31 }
32 #[allow(unused_variables)]
33 fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Vec<Action> {
34 vec![]
35 }
36 #[allow(unused_variables)]
37 fn dispatch(&mut self, action: Action) -> Option<Action> {
38 None
39 }
40 fn render(&mut self, f: &mut Frame<'_>, rect: Rect);
41}