agent_core/tui/keys/mod.rs
1//! Customizable key handling for LLM TUI applications.
2//!
3//! This module provides a flexible key handling system that allows agents
4//! to customize keyboard bindings while providing sensible defaults.
5//!
6//! # Overview
7//!
8//! The key handling system consists of:
9//! - [`KeyHandler`] trait for full control over key processing
10//! - [`DefaultKeyHandler`] implementation with configurable bindings
11//! - [`KeyBindings`] for specifying which keys trigger which actions
12//! - [`KeyCombo`] for representing key combinations (key + modifiers)
13//!
14//! # Examples
15//!
16//! ## Using preset bindings
17//!
18//! ```ignore
19//! let core = AgentCore::new(&config)?
20//! .with_key_bindings(KeyBindings::minimal());
21//! ```
22//!
23//! ## Customizing specific bindings
24//!
25//! ```ignore
26//! let mut bindings = KeyBindings::emacs();
27//! bindings.quit = vec![KeyCombo::key(KeyCode::Esc)];
28//! bindings.enter_exit_mode = vec![]; // Disable Ctrl+D exit mode
29//! let core = AgentCore::new(&config)?
30//! .with_key_bindings(bindings);
31//! ```
32//!
33//! ## Full custom handler
34//!
35//! ```ignore
36//! struct VimKeyHandler { mode: VimMode }
37//! impl KeyHandler for VimKeyHandler {
38//! fn handle_key(&mut self, key: KeyEvent, ctx: &KeyContext) -> AppKeyResult {
39//! // Implement vim-style modal editing
40//! }
41//! }
42//! let core = AgentCore::new(&config)?
43//! .with_key_handler(VimKeyHandler { mode: VimMode::Normal });
44//! ```
45
46mod bindings;
47mod exit;
48mod handler;
49mod nav;
50mod types;
51
52// Re-export all public types
53pub use bindings::KeyBindings;
54pub use exit::{ExitHandler, ExitState};
55pub use handler::{ComposedKeyHandler, DefaultKeyHandler, KeyHandler};
56pub use nav::NavigationHelper;
57pub use types::{AppKeyAction, AppKeyResult, KeyCombo, KeyContext};