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
impl DefaultKeyHandler
Sourcepub fn new(bindings: KeyBindings) -> Self
pub fn new(bindings: KeyBindings) -> Self
Create a new handler with the given bindings.
Sourcepub fn bindings(&self) -> &KeyBindings
pub fn bindings(&self) -> &KeyBindings
Get a reference to the key bindings.
Sourcepub fn with_custom_binding<F>(self, combo: KeyCombo, action_fn: F) -> Self
pub fn with_custom_binding<F>(self, combo: KeyCombo, action_fn: F) -> Self
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 bindaction_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
impl Default for DefaultKeyHandler
Source§impl KeyHandler for DefaultKeyHandler
impl KeyHandler for DefaultKeyHandler
Source§fn handle_key(&mut self, key: KeyEvent, context: &KeyContext) -> AppKeyResult
fn handle_key(&mut self, key: KeyEvent, context: &KeyContext) -> AppKeyResult
Source§fn status_hint(&self) -> Option<String>
fn status_hint(&self) -> Option<String>
Source§fn bindings(&self) -> &KeyBindings
fn bindings(&self) -> &KeyBindings
Auto Trait Implementations§
impl Freeze for DefaultKeyHandler
impl !RefUnwindSafe for DefaultKeyHandler
impl Send for DefaultKeyHandler
impl Sync for DefaultKeyHandler
impl Unpin for DefaultKeyHandler
impl !UnwindSafe for DefaultKeyHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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