Expand description
Key handling and bindings. 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:
KeyHandlertrait for full control over key processingDefaultKeyHandlerimplementation with configurable bindingsKeyBindingsfor specifying which keys trigger which actionsKeyCombofor representing key combinations (key + modifiers)
§Examples
§Using preset bindings
ⓘ
let core = AgentCore::new(&config)?
.with_key_bindings(KeyBindings::minimal());§Customizing specific bindings
ⓘ
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
ⓘ
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 });Structs§
- Composed
KeyHandler - A composable key handler wrapper with pre-processing hooks.
- Default
KeyHandler - Default key handler with configurable bindings.
- KeyBindings
- Key binding configuration.
- KeyCombo
- A key combination (key + modifiers).
- KeyContext
- Context provided to the KeyHandler.
- Navigation
Helper - Helper for widgets to check navigation keys against configured bindings.
Enums§
- AppKey
Action - Application-level key actions.
- AppKey
Result - Result of handling a key event at the App level.
- Exit
State - Exit confirmation state for key handlers.
Traits§
- Exit
Handler - Optional hook for agent cleanup on exit.
- KeyHandler
- Trait for customizing key handling at the App level.