Skip to main content

ActionMapper

Struct ActionMapper 

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

PriorityConditionKeyAction
1modal_openEscDismissModal
2modal_openCtrl+CDismissModal
3input_nonemptyCtrl+CClearInput
4task_runningCtrl+CCancelTask
5idleCtrl+CQuit (configurable)
6view_overlayEscCloseOverlay
7input_nonemptyEscClearInput
8task_runningEscCancelTask
9alwaysEsc EscToggleTreeView
10alwaysCtrl+DSoftQuit
11alwaysCtrl+QHardQuit

§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

Source

pub fn new(config: ActionConfig) -> Self

Create a new action mapper with the given configuration.

Source

pub fn with_defaults() -> Self

Create a new action mapper with default configuration.

Source

pub fn from_env() -> Self

Create a new action mapper loading config from environment.

Source

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 process
  • state - Current application state flags
  • now - Current timestamp for sequence detection
Source

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 flags
  • now - Current timestamp
Source

pub fn is_pending_esc(&self) -> bool

Whether the mapper is waiting for a second Esc.

Source

pub fn reset(&mut self)

Reset the sequence detector state.

Any pending Esc is discarded.

Source

pub fn config(&self) -> &ActionConfig

Get a reference to the current configuration.

Source

pub fn set_config(&mut self, config: ActionConfig)

Update the configuration.

Trait Implementations§

Source§

impl Debug for ActionMapper

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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, 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, 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.