Module keys

Module keys 

Source
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:

  • 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

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§

ComposedKeyHandler
A composable key handler wrapper with pre-processing hooks.
DefaultKeyHandler
Default key handler with configurable bindings.
KeyBindings
Key binding configuration.
KeyCombo
A key combination (key + modifiers).
KeyContext
Context provided to the KeyHandler.
NavigationHelper
Helper for widgets to check navigation keys against configured bindings.

Enums§

AppKeyAction
Application-level key actions.
AppKeyResult
Result of handling a key event at the App level.
ExitState
Exit confirmation state for key handlers.

Traits§

ExitHandler
Optional hook for agent cleanup on exit.
KeyHandler
Trait for customizing key handling at the App level.