KeyHandler

Trait KeyHandler 

Source
pub trait KeyHandler: Send + 'static {
    // Required method
    fn handle_key(
        &mut self,
        key: KeyEvent,
        context: &KeyContext,
    ) -> AppKeyResult;

    // Provided method
    fn status_hint(&self) -> Option<String> { ... }
}
Expand description

Trait for customizing key handling at the App level.

Implement this to customize how keys are processed BEFORE they reach widgets or default text input handling.

§Key Flow

Key Press
    |
KeyHandler.handle_key(key, context)  <- context.widget_blocking tells if modal is open
    |
If NotHandled -> Widget dispatch (modals like QuestionPanel get the key)
    |
If still unhandled -> Default text input handling

Required Methods§

Source

fn handle_key(&mut self, key: KeyEvent, context: &KeyContext) -> AppKeyResult

Handle a key event.

Called for every key press. Return:

  • NotHandled to pass to widgets and default handling
  • Handled to consume the key
  • Action(...) to execute an app action
§Arguments
  • key - The key event
  • context - Current app context (input state, processing state, etc.)

Provided Methods§

Source

fn status_hint(&self) -> Option<String>

Get a status hint to display in the status bar.

This allows the handler to provide context-sensitive hints, such as “Press again to exit” when in exit confirmation mode.

Implementors§