2026-01-19 09:23:12 -05:00
|
|
|
#![allow(dead_code, unused_variables)]
|
|
|
|
|
|
2026-01-18 11:02:41 -05:00
|
|
|
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
2026-01-17 17:09:42 -05:00
|
|
|
|
|
|
|
|
pub enum Action {
|
2026-01-19 15:03:50 -05:00
|
|
|
/// Exit the application.
|
2026-01-17 17:09:42 -05:00
|
|
|
Quit,
|
2026-01-19 15:03:50 -05:00
|
|
|
|
|
|
|
|
/// The input was checked by the Component and had no effect.
|
|
|
|
|
Noop,
|
|
|
|
|
|
|
|
|
|
/// Pass input to another component or external handler.
|
|
|
|
|
/// Similar to Noop with the added context that externally handled input may have had an impact.
|
|
|
|
|
Pass,
|
|
|
|
|
|
|
|
|
|
/// Save the current file.
|
|
|
|
|
Save,
|
|
|
|
|
|
|
|
|
|
/// The input was handled by a Component and should not be passed to the next component.
|
|
|
|
|
Handled,
|
2026-01-17 17:09:42 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-19 09:23:12 -05:00
|
|
|
pub trait Component {
|
2026-01-19 15:03:50 -05:00
|
|
|
/// Returns a unique identifier for the component.
|
|
|
|
|
/// This is used for lookup in a container of Components.
|
|
|
|
|
fn id(&self) -> &str;
|
|
|
|
|
|
2026-01-18 11:02:41 -05:00
|
|
|
fn handle_event(&mut self, event: Event) -> Action {
|
|
|
|
|
match event {
|
|
|
|
|
Event::Key(key_event) => self.handle_key_events(key_event),
|
|
|
|
|
_ => Action::Noop,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 09:23:12 -05:00
|
|
|
fn handle_key_events(&mut self, key: KeyEvent) -> Action {
|
2026-01-18 10:09:28 -05:00
|
|
|
Action::Noop
|
2026-01-17 17:09:42 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-19 09:23:12 -05:00
|
|
|
fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Action {
|
2026-01-17 17:09:42 -05:00
|
|
|
Action::Noop
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 09:23:12 -05:00
|
|
|
fn update(&mut self, action: Action) -> Action {
|
2026-01-17 17:09:42 -05:00
|
|
|
Action::Noop
|
|
|
|
|
}
|
|
|
|
|
}
|