pub struct ActionMapper { /* private fields */ }Expand description
Maps key events to high-level actions based on application state.
The ActionMapper integrates the sequence detector and implements the
priority table from the keybinding policy specification (bd-2vne.1).
§Priority Order
Actions are resolved in priority order (first match wins):
| Priority | Condition | Key | Action |
|---|---|---|---|
| 1 | modal_open | Esc | DismissModal |
| 2 | modal_open | Ctrl+C | DismissModal |
| 3 | input_nonempty | Ctrl+C | ClearInput |
| 4 | task_running | Ctrl+C | CancelTask |
| 5 | idle | Ctrl+C | Quit (configurable) |
| 6 | view_overlay | Esc | CloseOverlay |
| 7 | input_nonempty | Esc | ClearInput |
| 8 | task_running | Esc | CancelTask |
| 9 | always | Esc Esc | ToggleTreeView |
| 10 | always | Ctrl+D | SoftQuit |
| 11 | always | Ctrl+Q | HardQuit |
§Usage
use std::time::Instant;
use ftui_core::keybinding::{ActionMapper, ActionConfig, AppState, Action};
use ftui_core::event::{KeyCode, KeyEvent, Modifiers};
let mut mapper = ActionMapper::new(ActionConfig::default());
let now = Instant::now();
let state = AppState::default();
let key = KeyEvent::new(KeyCode::Char('q')).with_modifiers(Modifiers::CTRL);
let action = mapper.map(&key, &state, now);
assert!(matches!(action, Some(Action::HardQuit)));Implementations§
Source§impl ActionMapper
impl ActionMapper
Sourcepub fn new(config: ActionConfig) -> Self
pub fn new(config: ActionConfig) -> Self
Create a new action mapper with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new action mapper with default configuration.
Sourcepub fn map(
&mut self,
event: &KeyEvent,
state: &AppState,
now: Instant,
) -> Option<Action>
pub fn map( &mut self, event: &KeyEvent, state: &AppState, now: Instant, ) -> Option<Action>
Map a key event to an action based on current application state.
Returns Some(action) if the key resolves to an action, or None
if the event should be ignored (e.g., Noop on Ctrl+C when idle).
§Arguments
event- The key event to processstate- Current application state flagsnow- Current timestamp for sequence detection
Sourcepub fn check_timeout(
&mut self,
state: &AppState,
now: Instant,
) -> Option<Action>
pub fn check_timeout( &mut self, state: &AppState, now: Instant, ) -> Option<Action>
Check for sequence timeout and return pending action if expired.
Call this periodically (e.g., on tick) to handle single Esc after the timeout window closes.
§Arguments
state- Current application state flagsnow- Current timestamp
Sourcepub fn is_pending_esc(&self) -> bool
pub fn is_pending_esc(&self) -> bool
Whether the mapper is waiting for a second Esc.
Sourcepub fn config(&self) -> &ActionConfig
pub fn config(&self) -> &ActionConfig
Get a reference to the current configuration.
Sourcepub fn set_config(&mut self, config: ActionConfig)
pub fn set_config(&mut self, config: ActionConfig)
Update the configuration.