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
impl KeySequenceInterpreter
Sourcepub fn new(config: KeySequenceConfig) -> Self
pub fn new(config: KeySequenceConfig) -> Self
Create a new key sequence interpreter with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new interpreter with default configuration.
Sourcepub fn feed(&mut self, event: &KeyEvent, now: Instant) -> KeySequenceAction
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:
Emit: Pass this key through immediatelyEmitSequence: A sequence was detectedPending: Waiting for more keys
§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.
Sourcepub fn check_timeout(&mut self, now: Instant) -> Option<Vec<KeySequenceAction>>
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.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Returns true if there are pending keys waiting for a potential sequence.
Sourcepub fn time_until_timeout(&self, now: Instant) -> Option<Duration>
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.
Sourcepub fn flush(&mut self) -> Vec<KeySequenceAction>
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).
Sourcepub fn config(&self) -> &KeySequenceConfig
pub fn config(&self) -> &KeySequenceConfig
Get a reference to the current configuration.
Sourcepub fn set_config(&mut self, config: KeySequenceConfig)
pub fn set_config(&mut self, config: KeySequenceConfig)
Update the configuration.
Note: This does not affect keys already in the buffer.