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, orTripleClick. - 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
- Drag and Click never both emit for the same mouse-down → mouse-up interaction.
If a drag starts, the mouse-up produces
DragEnd, notClick. - Click multiplicity is monotonically increasing within a multi-click window:
Click→DoubleClick→TripleClick. Chordsequences are always non-empty.- After
reset(), all state machines return to their initial idle state. DragCancelis emitted if Escape is pressed during a drag.
§Failure Modes
- If the chord timeout expires mid-sequence, the chord buffer is cleared and
no
Chordevent 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 emitDragCancel(the caller handles focus-loss cancellation).
Structs§
- Gesture
Config - Thresholds and timeouts for gesture recognition.
- Gesture
Recognizer - Stateful gesture recognizer that transforms raw events into semantic events.