Skip to content

feat(term): decode SGR mouse reports in the wasm read-key - #1094

Merged
mparrett merged 1 commit into
nooga:mainfrom
mparrett:wasm-mouse-decode
Oct 28, 2026
Merged

mparrett merged 1 commit into
nooga:mainfrom
mparrett:wasm-mouse-decode

Conversation

@mparrett

Copy link
Copy Markdown
Collaborator

Why

#313 added SGR mouse decoding to the native term/read-key and left the wasm read-key returning the raw report string, noted there as a follow-up. A program that enables mouse reporting therefore gets {:type :mouse :action :press :button :left :x 10 :y 5 :mods #{}} in a terminal and "\e[<0;10;5M" in the browser. A game that steers by mouse works natively and silently ignores the mouse under lg -w.

What

  • New keyValue (in pkg/rt/key_value.go, no build tag) turns one key-source token into read-key's return: nil for "", the tagged map for an SGR mouse report, otherwise the string. The native and wasm read-key both call it, so the two can't drift apart.
  • mouseEventMap moves there unchanged from the native-only term.go, which is why the wasm build couldn't use it.
  • The enable-mouse comment in term_wasm.go no longer says the decode is missing.

Plan 9's read-key is unchanged.

Verification

  • TestKeyValue covers nil, plain keys, and a modified mouse release (:mods #{:shift :ctrl}); go test -short ./pkg/rt/ passes.
  • GOOS=js GOARCH=wasm go build ./pkg/rt/ and the Plan 9 build pass.
  • End to end in Chromium: a breakout game built with lg -w against this branch, with 1003 + 1006 reporting on. The paddle follows the mouse to either side of the board; on main it stays put while the same reports arrive as strings.

🤖 Generated with Claude Code

@mparrett
mparrett requested review from nnunley and nooga October 22, 2026 20:52
@mparrett

Copy link
Copy Markdown
Collaborator Author

Self-review found nothing actionable at 54b54162.

The extraction preserves native behavior and correctly adds mouse maps to WebAssembly read-key.

Verified:

  • Focused input tests pass natively and in WebAssembly.
  • Six term/read-key integration checks pass on both platforms, covering mouse events, keyboard strings, malformed reports, and EOF.
  • WebAssembly and Plan 9 builds pass.
  • Generated manifests are fresh; CI is green.

Local full-suite verification was limited by sandbox port restrictions and unrelated WebAssembly test compilation errors.

@nooga nooga left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Sharing keyValue between native and wasm read-key keeps the two from drifting.

Nit: pkg/rt/key_value.go has no copyright/SPDX header like its neighbours.

The wasm read-key returned mouse reports as raw escape strings, so a
program that enables mouse reporting got a map on native and a string in
the browser. Both read-keys now go through keyValue, which turns a report
into the tagged map from nooga#313. mouseEventMap moves out of the native-only
term.go so the wasm build can reach it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mparrett
mparrett merged commit d1cf427 into nooga:main Oct 28, 2026
21 checks passed
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.

2 participants