#![allow(dead_code, unused_variables)] use anyhow::Result; use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent}; pub enum Action { /// Exit the application. Quit, /// 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, } pub trait Component { /// Returns a unique identifier for the component. /// This is used for lookup in a container of Components. fn id(&self) -> &str; fn handle_event(&mut self, event: Event) -> Result { match event { Event::Key(key_event) => self.handle_key_events(key_event), _ => Ok(Action::Noop), } } fn handle_key_events(&mut self, key: KeyEvent) -> Result { Ok(Action::Noop) } fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Result { Ok(Action::Noop) } fn update(&mut self, action: Action) -> Result { Ok(Action::Noop) } }