iOS: render terminal full height and pin its bottom to the composer bar

Merged
AZ
3mo ago
+906-1172

Problem

In the iOS workspace-detail terminal, dismissing the keyboard pushed the terminal down and only then resized it to full height. The grid resized on every keyboard toggle, so the UIKit keyboard animation and the async grid renegotiation (capacity report → daemon echo → remote reflow) ran on different timelines. A pile of machinery (defer-shrink, provisional render pins, cursor-absorb math, presentation-layer rebasing, settle folds) existed only to mask that gap, and the dismissal leg still leaked through.

Fix

Delete the cause instead of masking it: the keyboard is no longer a grid input.

  • TerminalLetterboxGeometry.terminalContainerSize drops the keyboardHeight parameter. The grid always has its keyboard-down size, so a keyboard toggle runs no set_size, emits no capacity report, and no longer reflows the shared PTY — the Mac terminal stops resizing whenever the phone keyboard toggles.
  • GhosttySurfaceHostView pins the full-height render with one constraint: renderWrapper.bottom == dock.top + steadyChromeReservation. Keyboard motion is a single animated layout pass that moves the dock; the render rides it and the top rows clip behind the screen top. With the keyboard down the constant places the wrapper exactly at its natural position, so steady-state layout is unchanged.
  • Dock seat authority: UIKeyboardLayoutGuide where it works (chrome visible, non-iOS-27); the plain bottom constraint on iOS 27 and while chrome is hidden (the guide's safe-area fallback would float the hidden dock 34pt above the screen bottom).
  • Deleted: wrapper transform + rebase + settle fold, keyboardPresentationTransitionActive freezes, deferShrinkResize, provisional pins, cursor-absorb math, stale-live viewport clamps, renderPinnedBottomEdge, drawableContainerSize. Net −380 lines of transition machinery.
  • Snapshot dock frames are now keyboard-invariant surface coordinates (the dock always sits at the viewport bottom there); the composer dock probe emits keyboardDockTargetTop on the same basis.

Tests (red → green commits)

  • Commit 1 (red): TerminalViewportSpacingTests now asserts keyboard toggles emit no capacity report and leave grid + render untouched; stale-echo and dropped-echo coverage drives renegotiation through the composer band (still a real grid input); the mac-constrained stretch persists through keyboard toggles.
  • Commit 2 (green): implementation, plus TerminalKeyboardFullHeightPinTests (coordinator keyboard-invariance; host-level test that the render bottom stays glued to a riding dock seat with zero reports) and updated TerminalLetterboxGeometryTests.

Blank-space absorption

While the content bottom fits above the composer bar, blank rows absorb the keyboard: the terminal stays top-pinned under the navigation bar and the keyboard covers only empty space (the post-clear case). As content grows the render transitions continuously into the full bottom-pin, followed per-frame while the keyboard is up. The slack is a third term on the same wrapper constraint (renderWrapper.bottom == dock.top + chrome + slack, slack = min(blankBelowContent, intrusion)); alternate-screen apps always bottom-pin (a TUI's cursor says nothing about safe-to-cover rows). The dock seam contract is gap == keyboardSlack, exposed in the composer dock probe and asserted by the updated UITest helper.

HIG

Checked Virtual keyboards: "Use the keyboard layout guide to make the keyboard feel like an integrated part of your interface" and to "keep important parts of your interface visible while the virtual keyboard is onscreen." The dock (composer bar + toolbar) stays seated on the keyboard layout guide where the OS supports it, and the content that matters (prompt/cursor rows, composer) stays visible above the keyboard. Deliberate deviation: the terminal translates behind the keyboard rather than compressing, because compressing means reflowing a PTY shared with the Mac.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Render the iOS terminal at full height and pin its bottom to the composer bar; keyboard toggles no longer resize the grid or reflow the shared PTY. Dock seating is now notification-driven on all iOS versions with healing for detached transitions, removing the dismissal glitch and keeping layout stable.

  • Grid is keyboard-invariant: drop keyboard-height sizing, emit no capacity reports on toggles, and stop Mac-side resizes when the phone keyboard changes.

  • Host layout uses one constraint: renderWrapper.bottom = dock.top + steady chrome + slack, where slack = min(blankBelowContent, keyboard intrusion); alternate-screen apps disable slack. Host forwards window-level safe-area changes to trigger a grid resync, and strips in-flight animations on window detach.

  • SwiftUI hosting ignores the keyboard safe area at the bottom to keep the representable size invariant; the representable keeps hostedAltScreenActive live across mode flips.

  • Content-bottom measurement reads the last non-whitespace rendered row on the serial output queue, runs immediately on keyboard raise, throttles (hidden ~1 Hz, visible ~4 Hz), and stays viewport-bounded.

  • Tests/infra: add TerminalKeyboardFullHeightPinTests; update spacing/UI tests for the dock seam and keyboard invariance; import QuartzCore for replay tests; restore the ghostty submodule pointer; drive chrome-hidden tests via internal setChromeHidden.

  • Migration: remove TerminalLetterboxGeometry.drawableContainerSize and all keyboard-height-based sizing. Keyboard toggles must not change font size or grid size (adopt main’s letterbox-at-base-font contract).

Summary by CodeRabbit

  • Bug Fixes

    • Improved keyboard handling so the terminal dock moves smoothly without resizing the terminal grid or triggering unnecessary viewport renegotiation.
    • Preserved terminal rendering, font sizing, and viewport stability while the keyboard appears or disappears.
    • Improved layout behavior when toolbars, composers, safe areas, or other bottom controls are shown or hidden.
    • Fixed stale viewport and render-position issues during keyboard transitions and layout changes.
  • Tests

    • Added coverage for keyboard pinning, chrome-hidden layouts, viewport stability, keyboard spacing, and transition behavior.