Skip to main content

KeySequenceInterpreter

Struct KeySequenceInterpreter 

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

Stateful interpreter for multi-key sequences.

Feed key events via feed and periodically call check_timeout to handle expired sequences.

Implementations§

Source§

impl KeySequenceInterpreter

Source

pub fn new(config: KeySequenceConfig) -> Self

Create a new key sequence interpreter with the given configuration.

Source

pub fn with_defaults() -> Self

Create a new interpreter with default configuration.

Source

pub fn feed(&mut self, event: &KeyEvent, now: Instant) -> KeySequenceAction

Feed a key event into the interpreter.

Returns an action indicating what the caller should do:

§Key Event Filtering

Only key press events are processed. Release and repeat events are passed through immediately.

§Timeout Handling

This method does NOT automatically handle timeouts. Callers should periodically call check_timeout (e.g., on tick) to flush expired sequences. If a timeout has expired and you call feed() without calling check_timeout() first, buffered keys may be lost.

Source

pub fn check_timeout(&mut self, now: Instant) -> Option<Vec<KeySequenceAction>>

Check if the sequence timeout has expired.

Call this periodically (e.g., on tick) to flush expired sequences. Returns buffered keys as individual Emit actions if the timeout has expired.

Returns None if no timeout has expired or no keys are pending.

Source

pub fn has_pending(&self) -> bool

Returns true if there are pending keys waiting for a potential sequence.

Source

pub fn time_until_timeout(&self, now: Instant) -> Option<Duration>

Get the time remaining until the current pending sequence times out.

Returns None if there are no pending keys.

Source

pub fn reset(&mut self)

Reset all state, discarding any pending keys.

Source

pub fn flush(&mut self) -> Vec<KeySequenceAction>

Flush any pending keys immediately as individual emit actions.

Useful when the application needs to ensure all keys are processed before a state transition (e.g., on focus loss).

Source

pub fn config(&self) -> &KeySequenceConfig

Get a reference to the current configuration.

Source

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

Update the configuration.

Note: This does not affect keys already in the buffer.

Trait Implementations§

Source§

impl Debug for KeySequenceInterpreter

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.