Skip to main content

SequenceDetector

Struct SequenceDetector 

Source
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

Source

pub fn new(config: SequenceConfig) -> Self

Create a new sequence detector with the given configuration.

Source

pub fn with_defaults() -> Self

Create a new sequence detector with default configuration.

Source

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.

Source

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.

Source

pub fn is_pending(&self) -> bool

Whether the detector is waiting for a second Esc.

Source

pub fn reset(&mut self)

Reset the detector to idle state.

Any pending Esc is discarded.

Source

pub fn config(&self) -> &SequenceConfig

Get a reference to the current configuration.

Source

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

Update the configuration.

Does not reset pending state.

Trait Implementations§

Source§

impl Debug for SequenceDetector

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.