Enable SGR mouse tracking and parse mouse escape sequences - #172
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR lays groundwork for future mouse support in the interactive TUI by enabling SGR mouse reporting and introducing a small parser + test suite for SGR mouse escape sequences.
Changes:
- Enable SGR mouse reporting in
runInteractive()and add a hook in the stdin loop to detect mouse sequences. - Add
src/render/mouse.tswith an SGR mouse escape sequence parser returning structured mouse events (ornullon non-matches). - Add unit tests for the parser in
src/render/mouse.test.ts.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/tui.ts | Enables/disables SGR mouse reporting and attempts to parse incoming stdin chunks as mouse events before keyboard handling. |
| src/render/mouse.ts | Implements parseMouseEvent() for SGR \x1b[<b;x;yM/m sequences. |
| src/render/mouse.test.ts | Adds unit tests for valid and malformed SGR mouse sequences. |
Suppressed comments (1)
src/tui.ts:272
- Mouse reporting is disabled in
exit(), butrunInteractive()has other termination paths that callprocess.exit(0)after doing partial cleanup (e.g. the Enter/confirm-selection branch later in the loop) and will now skip the mouse-disable sequence. To avoid leaving the user’s terminal with mouse reporting still enabled, consider centralizing all exits through thisexit()helper (or ensuring everyprocess.exitpath disables?1000/?1006).
// ─── Exit handler for cleanup ────────────────────────────────────────────
const exit = () => {
// Disable SGR mouse reporting and clear terminal
process.stdout.write("\x1b[?1000l\x1b[?1006l");
process.stdout.write(ANSI_CLEAR);
process.stdin.setRawMode(false);
process.off("SIGWINCH", onResize);
process.exit(0);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Implement mouse tracking foundation for interactive TUI (#167): - Add src/render/mouse.ts with SGR parser for mouse events - Parser recognizes button codes, coordinates, press/release - Enable mouse tracking (\x1b[?1000h\x1b[?1006h) on TUI start - Disable tracking (\x1b[?1000l\x1b[?1006l) on exit - Wire parser into stdin loop in tui.ts; silently ignore unrecognized sequences - 15 unit tests with 100% coverage for parseMouseEvent - All validation checks pass (test, lint, format, knip, build)
shouze
force-pushed
the
feat/mouse-tracking-foundation
branch
from
August 23, 2026 18:53
78e051c to
19872c3
Compare
|
Coverage after merging feat/mouse-tracking-foundation into feat/mouse-ui-checkbox will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Coverage after merging feat/mouse-tracking-foundation into feat/mouse-ui-checkbox will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Establishes the foundation for mouse support in the interactive TUI by enabling SGR (Select Graphic Rendition) terminal mouse reporting. This allows the terminal to send mouse events (clicks, wheel scrolling) to the application in a structured format.
Changes
src/render/mouse.tswith SGR mouse event parser\x1b[<button;x;yM(press) orm(release)src/render/mouse.test.tswith 15 unit tests (100% coverage)src/tui.tsto enable SGR on startup and disable on exitHow did you verify your code works?
Closes #167