Skip to content

add SGR mouse parsing on POSIX while preserving legacy X10 behavior - #289

Open
mastaab wants to merge 2 commits into
ajalt:masterfrom
mastaab:pr/mouse-sgr
Open

add SGR mouse parsing on POSIX while preserving legacy X10 behavior#289
mastaab wants to merge 2 commits into
ajalt:masterfrom
mastaab:pr/mouse-sgr

Conversation

@mastaab

@mastaab mastaab commented Mar 2, 2026

Copy link
Copy Markdown

Summary

This PR adds SGR mouse event support on POSIX terminals without breaking existing X10-compatible behavior.

  • parse SGR mouse sequences (CSI < cb;x;y M/m) in PosixEventParser
  • keep legacy X10 parsing (CSI M ...) and preserve its historical button mapping behavior
  • use spec-correct button mapping for SGR events
  • enable both mouse encodings in raw mode (1005 + 1006) alongside existing tracking modes (1000/1002/1003)
  • disable both 1005 and 1006 when leaving raw mode

Why

Modern terminal emulators commonly support and prefer SGR mouse reporting (1006) for richer, unambiguous mouse data (larger coordinates and explicit press/release suffixes).
Examples include Ghostty and WezTerm (also supported by Kitty and recent iTerm2).
Adding SGR support improves interoperability on modern terminals, while preserving X10 behavior avoids regressions for existing Mordant consumers that rely on legacy decoding semantics.

Compatibility Notes

  • X10 path: unchanged behavior for button mapping (backward compatible)
  • SGR path: uses spec-correct middle/right decoding
  • Existing mouse tracking modes (Normal, Button, Any) continue to work as before

Tests

Added/updated PosixEventParser tests to cover:

  • SGR wheel events
  • SGR press/release parsing
  • SGR modifier decoding
  • legacy X10 wheel compatibility
  • legacy X10 middle/right mapping compatibility
  • mixed stream parsing (SGR followed by X10)

Enable 1006 mouse mode and parse SGR mouse sequences while preserving legacy X10 support. This removes ambiguous wheel/button decoding and adds parser tests for wheel, press/release, modifiers, and motion-bit handling.
Keep legacy X10 button mapping behavior while using spec-correct mapping for SGR sequences to avoid regressions in existing consumers.

Also enable both 1005 and 1006 mouse modes on POSIX and add parser tests covering legacy mapping and mixed SGR/X10 event streams.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant