Skip to content

fix(web): type German macOS Option characters in the Ghostty terminal - #14735

Open
macodev00 wants to merge 1 commit into
pingdotgg:mainfrom
macodev00:cursor/german-terminal-option-chars-redo2-bcae
Open

macodev00 wants to merge 1 commit into
pingdotgg:mainfrom
macodev00:cursor/german-terminal-option-chars-redo2-bcae

Conversation

@macodev00

Copy link
Copy Markdown
Contributor

Problem

On a German Mac layout, @ is Option+L. The desktop terminal and the web app share this Ghostty surface, and both forwarded Option as Alt into libghostty-vt. That WASM build is not Darwin, so Ghostty's macos-option-as-alt = false path never runs. DEC 1036 turns Option+L into ESC @ (readline set-mark), so nothing is typed. The same encoding drops the rest of that Option layer (€, ~, []{}|, \).

Electron does not set AltGraph for Option, so the existing AltGr bypass does not apply. Option+arrow word motion is a separate path.

Fixes #13046

Supersedes #14576

Why

Marking Alt consumed still leaves the raw Alt bit set. modifyOtherKeys mode 2 and Kitty report-all read that bit and emit an Alt sequence even when Alt is also consumed. The raw Alt bit has to be cleared when Option composition is consumed. Shift is cleared only when it participated in that composition. A lone Shift stays in the raw mask.

#14576 left navigator.platform unrestored whenever it was inherited. Node exposes platform on the prototype, so saving only an own-property descriptor did nothing and later tests kept the stub. Cleanup now restores a saved own descriptor, and deletes the temporary own property when there was none, inside finally, including when the stubbed call throws.

What Changed

A lone macOS Option that produces one character is consumed, and those consumed bits are cleared from the raw modifier mask before encoding. Ctrl, Meta, Option+arrow, and a lone Shift stay intact, including Shift+letter under modifyOtherKeys mode 2.

There is no Option-as-Meta setting. This matches Terminal.app with "Use Option as Meta key" off, and Ghostty's default. Option+letter chords that previously became ESC plus the unshifted letter now type the composed character.

Scope and approval

Triaged bug #13046 (accepted by juliusmarminge). The change is the terminal key encoder in the web surface the desktop app embeds. Mobile's native terminal is a different path and is unchanged.

Verification

From commit 4aeae6d73, Node 24.13.1 (v24.13.1).

Formatter, from the repo root:

./node_modules/.bin/vp fmt apps/web/src/terminal/ghostty/keyCodes.ts apps/web/src/terminal/ghostty/keyCodes.test.ts apps/web/src/terminal/ghostty/core.ts apps/web/src/terminal/ghostty/core.test.ts apps/web/src/terminal/ghostty/runtimeAbi.test.ts

Result, exit 0:

note: You are running `vp fmt` as a Vite+ built-in command. If you meant to run the fmt npm script, use `vpr fmt` instead.
Finished in 151ms on 5 files using 4 threads.

No further edits.

Lint, from the repo root:

./node_modules/.bin/vp lint apps/web/src/terminal/ghostty/keyCodes.ts apps/web/src/terminal/ghostty/core.ts apps/web/src/terminal/ghostty/core.test.ts apps/web/src/terminal/ghostty/keyCodes.test.ts apps/web/src/terminal/ghostty/runtimeAbi.test.ts

Result, exit 0. The only warning is the existing no-new-array note in ghosttyCellText:

apps/web/src/terminal/ghostty/core.ts:182:19: warning unicorn(no-new-array): Do not use `new Array(singleArgument)`.

Unit tests, from apps/web:

../../node_modules/.bin/vp test run --project unit src/terminal/ghostty/keyCodes.test.ts src/terminal/ghostty/runtimeAbi.test.ts src/terminal/ghostty/core.test.ts

Result, exit 0:

 RUN  v5.0.1 /workspace/apps/web

 Test Files  3 passed (3)
      Tests  35 passed (35)
   Start at  06:28:55
   Duration  6.11s (transform 52%, import 27%, tests 15%, setup 6%)

Typecheck, from the repo root:

./node_modules/.bin/vp run --filter @t3tools/web typecheck

Result, exit 0:

~/apps/web$ tsc --noEmit ⊘ cache disabled

The WASM tests assert the encoded bytes, not only the consumed-mod bitmask:

  • Default and Kitty disambiguate: raw Alt encodes ESC @ / CSI 64;3 u. Consumed Alt without clearing the raw bit is still an Alt sequence under modifyOtherKeys mode 2 (CSI 27;3;64~). The mask encodeKey sends encodes @.
  • Option+Shift+7 (\): leaving the composing Shift in the raw mask encodes CSI 27;2;92~. Clearing it encodes \.
  • Lone Shift+A under modifyOtherKeys mode 2 stays CSI 27;2;65~.
  • GhosttyTerminalCore.encodeKey on a MacIntel platform writes @, €, |, and \ in the default, modifyOtherKeys, and Kitty disambiguate modes, and the Kitty report-all sequence \x1b[64::108;;64u. Linux and Windows Alt still prefix ESC. Ctrl+C and Option+Left are unchanged.
  • navigator.platform is restored after every encodeKey test. An inherited platform (no own descriptor) is deleted again after a thrown stub, and an own descriptor is put back.

Limitations: checked on Linux x86_64, Node 24.13.1. In this runtime navigator.platform is the inherited value Linux x86_64, which is the case that previously leaked an own property.

Not checked on a physical German keyboard or Electron on macOS. The assertions pass a platform string into the same encoder the desktop app uses.

Option+letter chords that used to send ESC plus the unshifted letter now type the composed character. There is no setting to keep Option as Meta.

UI Changes

None visual. This changes the bytes the terminal key encoder sends for macOS Option compositions. There is no layout or rendering change to screenshot.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots (none: no visual change)
  • Video for interaction changes (none: the encoded key bytes are asserted directly in tests; no physical German Mac keyboard available)

On macOS, Option+L is @. The terminal forwarded Option as Alt into a
non-Darwin libghostty-vt build, so DEC 1036 sent ESC @. Marking Alt
consumed still left the raw Alt bit set, and modifyOtherKeys mode 2
encoded that as an Alt sequence.

Consume a lone macOS Option that produced a character, and clear those
consumed bits from the raw modifier mask before encoding. Ctrl, Meta,
Option+arrow, and a lone Shift stay intact. There is no Option-as-Meta
setting; this matches Terminal.app with that option off.

Tests that stub navigator.platform restore the previous own descriptor,
and delete the temporary own property when platform was inherited,
including when the stubbed call throws.
@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Oct 2, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Oct 2, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 4aeae6d

Macroscope's review found this PR approvable — This is a focused fix to existing Ghostty terminal key encoding for macOS Option-composed characters, with non-macOS behavior preserved and extensive unit/WASM coverage. It adds no schema, configuration, deployment, security, billing, or static-analysis changes.

Notes:

  • Diff unchanged. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 2, 2026 — with ChatGPT Codex Connector
@macroscopeapp
macroscopeapp Bot dismissed their stale review October 2, 2026 06:35

Dismissing prior approval to re-evaluate 4aeae6d

@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 656fc598-b0d4-4e46-bc76-e95df88df451

📥 Commits

Reviewing files that changed from the base of the PR and between 99e0852 and 4aeae6d.

📒 Files selected for processing (5)
  • apps/web/src/terminal/ghostty/core.test.ts
  • apps/web/src/terminal/ghostty/core.ts
  • apps/web/src/terminal/ghostty/keyCodes.test.ts
  • apps/web/src/terminal/ghostty/keyCodes.ts
  • apps/web/src/terminal/ghostty/runtimeAbi.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change updates Ghostty key modifier handling for character-producing Option input on macOS and iOS. It adds platform-aware modifier masks, passes both raw and consumed masks to key encoding, and tests the behavior across keyboard modes and platforms.

Changes

Option-Key Encoding

Layer / File(s) Summary
Modifier consumption and masks
apps/web/src/terminal/ghostty/keyCodes.ts, apps/web/src/terminal/ghostty/keyCodes.test.ts
ghosttyConsumedMods accepts a platform and identifies consumed Shift and Alt modifiers. ghosttyEncoderMods returns raw and consumed modifier masks. Tests cover platform-specific behavior and retained modifier bits.
Ghostty key encoding and validation
apps/web/src/terminal/ghostty/core.ts, apps/web/src/terminal/ghostty/core.test.ts, apps/web/src/terminal/ghostty/runtimeAbi.test.ts
encodeKey passes both modifier masks to the key event. Tests cover Option-character encoding across keyboard modes, platform-specific Alt behavior, and keyboard-layout codepoints.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • pingdotgg/t3code#14576: Both changes address macOS German Option-character input in GhosttyTerminalCore.encodeKey and clear consumed Option bits before encoding.

Merge Risk: ⚪ Minimal · up to 4aeae

This change makes Option-produced characters, such as @ on a German Mac keyboard, type correctly in the desktop terminal. Ctrl, Meta, and Option+arrow behavior is kept, and Linux and Windows are unchanged. No merge-blocking problems were found. It was not tested on a real German keyboard on macOS.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 4aeae

The change is limited to interpreting keyboard modifiers within an existing terminal session. No additional access or authority was identified. Remaining uncertainty concerns failure recovery and behavior beyond the existing terminal-input callback.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated changed exposure is keyboard-byte interpretation for the already selected terminal through the existing input callback. The inspected change does not expand terminal selection or caller authority; broader downstream session ownership remains outside this assessment.

Trust Boundaries and Controls

  • observed — The production path retains the existing shortcut and composition gates before encoding and forwarding keyboard input. The mask change does not add an event source or replace those gates.

Resilience and Maintainability Implications

  • observed — Each encode checks that the terminal is active, refreshes protocol options and overwrites the reused event fields before encoding. Press, repeat and release mapping and normal-path cleanup are unchanged. Exception-path cleanup limitations existed before this PR; direct exception-recovery and release-transition test coverage remains incomplete.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the web Ghostty terminal fix for macOS Option characters and follows the repository's conventional commit style.
Description check ✅ Passed The description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, linked issue, scope, test commands, results, limitations, and why…
Linked Issues check ✅ Passed The PR addresses [#13046]. ghosttyConsumedMods consumes macOS Option for single-character input without Ctrl or Meta. ghosttyEncoderMods clears the consumed Alt bit before encoding. `GhosttyTermin…
Out of Scope Changes check ✅ Passed The changes stay within [#13046]. They update web terminal modifier handling, recover keyboard-layout data for Option characters, update the encoder integration, and add focused unit and WASM tests. T…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 5 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@jcxplorer

Copy link
Copy Markdown

Built the desktop app locally (main + this PR at 4aeae6d) and tested it on macOS 27.0.1 with a Finnish keyboard layout. Option-composed characters now type correctly in the terminal: @ (Option+2), | (Option+7), [ ] (Option+8/9), and with Option+Shift, \ (Option+Shift+7) and { } (Option+Shift+8/9). Ctrl+C and Option+←/→ word jumps still behave as before.

@fmajestic

fmajestic commented Oct 7, 2026 •

Copy link
Copy Markdown

I can also confirm, running this locally with a Croatian keyboard layout, all the option+key special chars type properly:

opt+1 = ~
opt+3 = ^
opt+7 = `
opt+q = \
opt+w = |
opt+f = [
opt+g = ]
opt+v = @
opt+b = {
opt+n = }
opt+, = <
opt+. = >

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot type @ char in Terminal on MacOS with German Keyboard Layout

4 participants