eazygit 0.5.1

A fast TUI for Git with staging, conflicts, rebase, and palette-first UX
Documentation
use crate::app::{AppState, Action};
use crate::errors::ComponentError;
use crate::input::InputEvent;
use ratatui::Frame;
use ratatui::layout::Rect;
use tracing::instrument;

/// Component trait defining the lifecycle of UI components.
/// Similar to React's component lifecycle: init → handle_event → update → render
pub trait Component: Send + Sync {
    /// Initialize component (called once on mount)
    /// This is where component-specific setup happens
    #[instrument(skip(self, state), fields(component = self.name()))]
    fn init(&mut self, state: &AppState) -> Result<(), ComponentError> {
        let _ = state; // Suppress unused warning
        Ok(())
    }
    
    /// Handle input events (keyboard, mouse, async)
    /// Returns an Action if the component handles the event, None otherwise
    #[instrument(skip(self, state), fields(component = self.name()))]
    fn handle_event(
        &mut self,
        event: InputEvent,
        state: &AppState,
    ) -> Result<Option<Action>, ComponentError> {
        let _ = (event, state); // Suppress unused warnings
        Ok(None)
    }
    
    /// Update component state based on action
    /// This is where component can trigger side effects (e.g., refresh status)
    #[instrument(skip(self, state), fields(component = self.name()))]
    fn update(
        &mut self,
        action: Action,
        state: &mut AppState,
    ) -> Result<(), ComponentError> {
        let _ = (action, state); // Suppress unused warnings
        Ok(())
    }
    
    /// Render component to frame
    /// This is where component draws its UI
    #[allow(dead_code)]
    #[instrument(skip(self, state), fields(component = self.name()))]
    fn render(&mut self, frame: &mut Frame, area: Rect, state: &AppState) {
        let _ = (frame, area, state); // Suppress unused warnings
    }
    
    /// Component name (for debugging and logging)
    fn name(&self) -> &'static str;
}