Skip to main content

Module gesture

Module gesture 

Source
Expand description

Gesture recognition: transforms raw terminal events into semantic events.

GestureRecognizer is a stateful processor that converts raw Event sequences (mouse clicks, key presses, etc.) into high-level SemanticEvents (double-click, drag, chord, etc.).

§State Machine

The recognizer tracks several concurrent state machines:

  • Click detector: Tracks consecutive clicks at the same position to emit Click, DoubleClick, or TripleClick.
  • Drag detector: Monitors mouse-down → move → mouse-up sequences, emitting DragStart / DragMove / DragEnd / DragCancel.
  • Long press detector: Fires when mouse is held stationary beyond a threshold.
  • Chord detector: Accumulates modifier+key sequences within a timeout window.

§Invariants

  1. Drag and Click never both emit for the same mouse-down → mouse-up interaction. If a drag starts, the mouse-up produces DragEnd, not Click.
  2. Click multiplicity is monotonically increasing within a multi-click window: ClickDoubleClickTripleClick.
  3. Chord sequences are always non-empty.
  4. After reset(), all state machines return to their initial idle state.
  5. DragCancel is emitted if Escape is pressed during a drag.

§Failure Modes

  • If the chord timeout expires mid-sequence, the chord buffer is cleared and no Chord event is emitted (raw keys are still delivered by the caller).
  • If focus is lost during a drag, the caller should call reset() which will not emit DragCancel (the caller handles focus-loss cancellation).

Structs§

GestureConfig
Thresholds and timeouts for gesture recognition.
GestureRecognizer
Stateful gesture recognizer that transforms raw events into semantic events.