Skip to main content

infinity_agent_cli/
component.rs

1use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
2
3/// Whether the key event represents a cancel gesture (Esc or Ctrl+C).
4pub fn is_cancel(key: &KeyEvent) -> bool {
5    key.code == KeyCode::Esc
6        || (key.code == KeyCode::Char('c') && key.modifiers.contains(KeyModifiers::CONTROL))
7}
8
9/// Whether a keystroke was consumed by a component.
10pub enum KeyResult {
11    /// The component handled the keystroke.
12    Captured,
13    /// The component did not handle the keystroke; pass it along.
14    NotCaptured,
15}
16
17/// Trait for TUI components that can handle keyboard input.
18pub trait Component {
19    fn handle_keystroke(&mut self, key: KeyEvent) -> KeyResult;
20}