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