pub struct SequenceDetector { /* private fields */ }Expand description
Stateful detector for multi-key sequences (currently Esc Esc).
This detector transforms a stream of KeyEvents into SequenceOutputs,
detecting Esc Esc sequences with configurable timeout handling.
§Usage
Call feed for each key event. The detector returns:
Pending: First Esc received, waiting for more input or timeout.Esc: Single Esc was detected (after timeout or other key).EscEsc: Double Esc sequence was detected.PassThrough: Key is not Esc, pass through to normal handling.
Call check_timeout periodically (e.g., on
tick) to emit pending single Esc after timeout expires.
Implementations§
Source§impl SequenceDetector
impl SequenceDetector
Sourcepub fn new(config: SequenceConfig) -> Self
pub fn new(config: SequenceConfig) -> Self
Create a new sequence detector with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new sequence detector with default configuration.
Sourcepub fn feed(&mut self, event: &KeyEvent, now: Instant) -> SequenceOutput
pub fn feed(&mut self, event: &KeyEvent, now: Instant) -> SequenceOutput
Process a key event and return the sequence output.
Only key press events are considered; repeat and release are ignored.
Sourcepub fn check_timeout(&mut self, now: Instant) -> Option<SequenceOutput>
pub fn check_timeout(&mut self, now: Instant) -> Option<SequenceOutput>
Check for timeout and emit pending Esc if expired.
Call this periodically (e.g., on tick) to handle the case where the user pressed Esc once and is waiting.
Returns Some(SequenceOutput::Esc) if timeout expired,
None otherwise.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Whether the detector is waiting for a second Esc.
Sourcepub fn config(&self) -> &SequenceConfig
pub fn config(&self) -> &SequenceConfig
Get a reference to the current configuration.
Sourcepub fn set_config(&mut self, config: SequenceConfig)
pub fn set_config(&mut self, config: SequenceConfig)
Update the configuration.
Does not reset pending state.