DefaultKeyHandler

Struct DefaultKeyHandler 

Source
pub struct DefaultKeyHandler { /* private fields */ }
Expand description

Default key handler with configurable bindings.

This implementation uses KeyBindings to determine what actions to take for each key press. It handles the standard key processing flow while allowing customization of all bindings.

The handler manages exit confirmation state internally, so agents get the two-key exit flow (e.g., press Ctrl+D twice) without needing to track any state in the App.

§Custom Bindings

In addition to the standard bindings, you can add custom key bindings that trigger custom actions:

let handler = DefaultKeyHandler::new(KeyBindings::emacs())
    .with_custom_binding(KeyCombo::ctrl('t'), || {
        AppKeyAction::custom(MyCustomAction::ToggleSomething)
    });

Implementations§

Source§

impl DefaultKeyHandler

Source

pub fn new(bindings: KeyBindings) -> Self

Create a new handler with the given bindings.

Source

pub fn bindings(&self) -> &KeyBindings

Get a reference to the key bindings.

Source

pub fn with_custom_binding<F>(self, combo: KeyCombo, action_fn: F) -> Self
where F: Fn() -> AppKeyAction + Send + Sync + 'static,

Add a custom key binding that triggers a custom action.

Custom bindings are checked before standard bindings, allowing you to override default behavior or add new key combinations.

§Arguments
  • combo - The key combination to bind
  • action_fn - A function that returns the action to execute
§Example
let handler = DefaultKeyHandler::new(KeyBindings::emacs())
    .with_custom_binding(KeyCombo::ctrl('t'), || {
        AppKeyAction::custom(MyCustomAction::ToggleSomething)
    })
    .with_custom_binding(KeyCombo::alt('h'), || {
        AppKeyAction::custom(MyCustomAction::ShowHelp)
    });

Trait Implementations§

Source§

impl Default for DefaultKeyHandler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl KeyHandler for DefaultKeyHandler

Source§

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

Handle a key event. Read more
Source§

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

Get a status hint to display in the status bar. Read more
Source§

fn bindings(&self) -> &KeyBindings

Get a reference to the key bindings. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more