diff --git a/lib/cli/tui/framework/component.rs b/lib/cli/tui/framework/component.rs index 72e06cf..6546d9c 100644 --- a/lib/cli/tui/framework/component.rs +++ b/lib/cli/tui/framework/component.rs @@ -81,6 +81,9 @@ pub trait Component: Downcast { let action = match event { Some(Event::Key(key_event)) => self.handle_key_events(key_event)?, Some(Event::Mouse(mouse_event)) => self.handle_mouse_events(mouse_event)?, + Some(Event::Tick) => self.handle_tick_event()?, + Some(Event::Render) => self.handle_frame_event()?, + Some(Event::Paste(ref event)) => self.handle_paste_event(event.clone())?, _ => None, }; @@ -126,6 +129,48 @@ pub trait Component: Downcast { Ok(None) } + /// Handle Tick events and produce actions if necessary. + /// + /// # Arguments + /// + /// * `tick` - A tick event to be processed. + /// + /// # Returns + /// + /// * `Result>` - An action to be processed or none. + #[allow(unused_variables)] + fn handle_tick_event(&mut self) -> Result> { + Ok(None) + } + + /// Handle frame events and produce actions if necessary. + /// + /// # Arguments + /// + /// * `tick` - A tick event to be processed. + /// + /// # Returns + /// + /// * `Result>` - An action to be processed or none. + #[allow(unused_variables)] + fn handle_frame_event(&mut self) -> Result> { + Ok(None) + } + + /// Handle paste events and produce actions if necessary. + /// + /// # Arguments + /// + /// * `message` - A string message to be processed. + /// + /// # Returns + /// + /// * `Result>` - An action to be processed or none. + #[allow(unused_variables)] + fn handle_paste_event(&mut self, message: String) -> Result> { + Ok(None) + } + /// Update the state of the component based on a received action. If you want to override this /// method, you will lose calling the children's update methods. That's why we provide a helper /// function to update the children's state. Something like the following is recommended: