Repository navigation
fix(terminal): the mouse reaches a child that reads it - #312
Merged
Merged
Conversation
Only wheel notches were ever encoded to the PTY. A press, release, drag or motion over a TUI with mouse reporting on was consumed as a local text selection and the child never heard of it — so Claude Code's /diff and /resume, vim, lazygit, fzf and every other mouse-mode program got a wheel and nothing else. One predicate, three readers. `core::app::pointer` gains `MouseReporting` (the DECSET 1000 / 1002 / 1003 ladder) and `PointerEvent::route`, which answers Forward / Select / Nothing: under any mouse reporting the mouse is the child's, so what its mode covers is forwarded and the rest is dropped rather than selected. The terminal thread routes on its live mode (`session::pointer_input`), the MCP shell answers `forwarded` off the last `Screen`, and the canvas hands the bare gestures to the child through `Message::TermPointer` while a held modifier — Shift, the xterm override, or the link modifier — keeps the pointer for the terminal's own gestures. The mode bits are read in one place, a new `pty::mode` leaf both `input` and `grid` may import, since neither may import the other; `Screen` carries the reading as `mouse_reporting`. `wheel_bytes`' SGR/X10 body becomes the shared `mouse_report`, which `mouse_bytes` extends to press, release, drag and motion — no second encoder. The write path is one `forward_mouse`. Closes #155
…rded mouse `mouse_in_session` documents its third answer and which of the two the program decides; the terminal page gains "When the program reads the mouse" with the Shift override; the live-bridge gaps table loses #155. AGENTS records the one-predicate-three-readers rule, the `pty::mode` leaf and why it exists, and where modifiers went. The roadmap entries that named #155 as blocked read it as fixed. Mutation testing on the changed files left one survivor in the diff, a `kind != Move` guard in the canvas hand-off that the link-modifier early return made unreachable; the guard is gone rather than tested.
The end-to-end claim behind the rung, made against a spawned shell running cat -v with mouse reporting on: the Screen reports the mode, the pointer is routed and encoded, and the child prints the SGR click it was sent.
This was referenced Sep 16, 2026
bastien-gallay
added a commit
that referenced
this pull request
Sep 16, 2026
…reaching the child (#314) * docs: the README, the book's tool count and four other surfaces catch up with the pointer reaching the child The two pointer PRs (#311, #312) and the review pass (#313) updated the book, AGENTS, the roadmap and the changelog and none of them opened README.md or docs/src/mcp/index.md. The README tool table listed fifteen tools with no mouse_in_session, its follow-up sentence still said the surface could press keys but not click and counted #300 among what remained, and its gesture paragraph promised a drag selects with no word for a program that owns the mouse; the book's index counted fifteen twice. live-bridge.md's follow-up header undercounted its own five-row table, PtyHost::pointer's doc-comment spoke of the mode gate in the future tense, f-mcp-pointer-terminal said Blocks for a bug that is closed, and f-mcp-attach named the tool count as fifteen in two places — a number that rots on every rung, now phrased as the set the spawned session gets. * docs(agents): an MCP rung owes the README table and the book's tool count — four in a row shipped without them Every rung merged since the README tool table was written (#215, #229, #281, #300) landed without touching README.md, each repaired by a later pass; verified with git show --stat on the four squashes. The book table in AGENTS now names README's table and follow-up sentence and the count in docs/src/mcp/index.md on the MCP-tool row, and .wrap.md records the fourth miss on the sections it already listed.
This was referenced Sep 21, 2026
Cmd+C in a mouse-mode Claude Code tab overwrites the clipboard with termherd's stale copy cache
#316
Closed
bastien-gallay
added a commit
that referenced
this pull request
Sep 22, 2026
… keeps no cache (#318) * docs: the copy chord's cache fallback is a defect where a program owns the mouse (#316) A drag in a Claude Code tab is the program's since #312, so the terminal never has a visible selection there — and the copy chord then writes its last-copied cache over the copy the program just made, reporting `ran`. Filed as #316; this caveats every surface that promised otherwise, adds the defect to each "what remains" list, and records the lesson beside the cache bullet in AGENTS.md. Nothing here describes the fix, which is still open. * fix(terminal): the copy chord asks the terminal for its selection and keeps no cache In a pane whose program reads the mouse an unshifted drag is the program's, so the terminal never selects there — and the chord, finding no visible spans, fell back to `Shell::selection`, a cache of the last text termherd had copied, and wrote it over the clipboard the program had just filled. Once anything had been copied anywhere, every chord in every such pane did this and reported `ran`. The terminal owns the selection, so it now answers whether one exists: `Screen::has_selection`, true for a non-empty selection whose rows the emulator still holds, on screen or scrolled into history — and false once a scroll past the scrollback rotated the selection off the rows it covered, where `selection_to_string` has nothing to read. The chord gates on that and sends `CopyTerminalSelection`, or refuses `inert / no-context`. The cache and both its writers are gone. The three-state copy test becomes two states on the screen's flag; the "prefers the live selection to the cache" test retires with the cache; two tests pin the scrolled-out copy and the inert chord after an earlier copy. Mutation testing on the diff: 12 mutants, 2 caught, 0 missed. Closes #316 * docs: the copy chord's caveats become the fixed behaviour (#316) The caveats the previous commit's sibling PR (#317) put on eight surfaces described an open defect; with the cache gone they describe the fix instead, and #316 leaves every "what remains" list. A changelog entry under Unreleased names the user-visible change, and the quality-bar bullet in AGENTS.md carries the lesson: a fallback that fires whenever a precondition is absent becomes a bug the day a feature makes that precondition permanently absent. * docs(wrap): caveats for a defect about to be fixed stay on the branch, not in their own PR PR #317 shipped eight caveats for #316 and was superseded by the fix PR an hour later; the note records the rule so the next wrap holds them instead. * docs(agents): the copy-cache bullet speaks of the cache in the past tense The bullet described the reordering that kept the cache as the current design; the cache is gone since the previous commit on this branch.
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.
Closes #155
What
A program with mouse reporting on — Claude Code's
/diffand/resume, vim, lazygit, fzf, less, tmux — now receives presses, releases, drags and (under 1003) bare moves, in the SGR or X10 encoding it negotiated. Only wheel notches were ever forwarded; a press was consumed as a local text selection and the child never heard of it.How — one predicate, three readers
MouseReporting { Click, Drag, Motion }is the DECSET 1000/1002/1003 ladder;routenever answersSelectunder any reporting (proptest) — the mouse is the child's, a motion it did not ask for is dropped, not selected.pty::modeleaf:input(encoder gate) andgrid(Screen.mouse_reporting) both need it and the module-boundary script forbids either importing the other.wheel_bytes' SGR/X10 body became the sharedmouse_report;mouse_bytesextends it to buttons and motion. It only encodes — the gate isroute's, asked by the caller.Message::TermPointer; Shift (xterm override) and the link modifier keep the pointer for the terminal's own gestures. Double-click word, shift-extend and link click never left the canvas.PointerOutcome::Forwarded; the shell answers off the lastScreen, the same lag class as its bounds check; the terminal decides again on its live mode.Out of scope, on purpose: modifier bits in the report (the event lost
modifiersin #311; it comes back as one shared type when a caller needs it), and folding the wheel intoPointerKind(its scrollback/alt-scroll fallback has no pointer equivalent).Tests
30 new:
routetable + PBT (core), SGR/X10 encoder incl. X10 saturation (pty::input), mode ladder (pty::mode),pointer_inputpure + a terminal-thread test asserting the bytes a click writes to the PTY (pty::session), snapshot ladder (pty::grid),forwardedoutcome (shell), the three words (handler), and the canvas hand-off: buttons, drag ≥ Drag, move = Motion, release after a forwarded press, Shift override, right press outranking paste.Mutants on the changed files: 103 caught · 0 missed in the diff (the 50 survivors are pre-existing
draw/live_hoverarithmetic incanvas.rs, swept because-fis file-level). One survivor in the diff was akind != Moveguard the link-modifier early return made unreachable; removed.Docs
Book:
mcp/live-bridge.md(third answer, who decides, gaps table),workspace/terminal.md("When the program reads the mouse"). AGENTS, CHANGELOG, roadmap entries that named #155 as blocked.Verification beyond CI
The rung this builds on (#300) exists so an agent can verify this:
mouse_in_sessionover a/resumelist in a Claude session should answerforwardedand move the highlight. Not yet run against a live TUI in this PR — a manual pass from the release app is the remaining check.