Repository navigation
fix(mocactl): redraw history on resize; cap live region to the window - #651
Conversation
Settled history is printed once through <Static>, wrapped at the width it was printed at; when the terminal width changed nothing re-printed it, so the terminal's own re-wrap left stray and duplicated box borders. A width change now waits for the resize to settle (RESIZE_SETTLE_MS) and calls the existing redraw() once. A streaming reply could grow the live region past the window height, which makes Ink clear and repaint the screen on every frame, so the input box jumped and flickered. The live region is now capped a row short of the window: an overlong reply is clipped from the top so its newest lines stay in view, and the overlay, input box and status line never shrink. The full reply still reaches history through <Static> once it settles. Pinning the input box to the bottom with a short transcript is left out: it needs a full-screen layout that replaces the print-once history design (spec §6.1). Fixes rossoctl#596 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Ed Snible <[email protected]>
20f1f81 to
5e17c13
Compare
huang195
left a comment
There was a problem hiding this comment.
The resize redraw is a clean debounce on the existing redraw(). It doesn't fire on the first render, and the cleanup cancels the timer on each new resize and on unmount. The rows - 1 cap matches Ink 8's rule for switching to full repaints (outputHeight >= rows). With overflowY="hidden" and flex-end, the newest lines stay in view, and the non-shrinking wrappers stop Yoga from squashing blocks. Both tests target the right behavior. LGTM.
One thing to be aware of, not blocking: CLEAR_SCREEN includes \e[3J, so every width change now clears the scrollback, including shell history from before mocactl started. Theme changes and the editor already did this. Resizing is a passive action, though, so users will hit it more often.
Author: esnible (MEMBER — maintainer)
Areas reviewed: TypeScript/React (Ink UI), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed off
CI status: passing
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Both fixes look right. The resize debounce is correct: bursts restart the timer, a return to the printed width cancels it, and the first render is skipped. The tests fail with the fix reverted, which is good. One suggestion inline: the outer maxHeight clips the overlay, input box and status line once they outgrow the window by themselves. That happens with Help in a session at 80×24. The L62-63 comment says Ink falls back to full repaints there instead.
Author: esnible (MEMBER, maintainer) · Areas: mocactl TUI (Ink), tests · Agent/IDE config: none · Commits: 1, signed-off · CI: green (k8s-kind-e2e pending at review time)
| {overlay ? ( | ||
| <Box marginTop={1} flexDirection="column"> | ||
| {overlay} | ||
| <Box flexDirection="column" maxHeight={Math.max(1, rows - 1)}> |
There was a problem hiding this comment.
suggestion: The outer maxHeight also applies when the flexShrink={0} children overflow on their own, and Ink then clips them rather than falling back to full repaints, so the comment at L62-63 is inaccurate. With Ink 8.0.0 (the lockfile version) the frame is the box's computed height, and rows past it are dropped.
That's reachable at the default 80×24 in a session: Help is the title, 16 commands, a blank line and INPUT_KEYS, which wraps to 2 lines at 80 columns. That's 20 lines, plus marginTop 1, the input box 3 and the status line 1, which makes 25 rows against a cap of 23. I rendered that tree in isolation, and the last two lines were ╭───╮ / │ type a message │: the bottom border and the status line are gone. A multi-line draft in the input box, or a short window (rows ≤ ~6), hits the same thing.
One option is to put the cap only on the live box, sized from what's left: measure the fixed tail with measureElement and set maxHeight={Math.max(0, rows - 1 - tailHeight)} on the clipped box. You could also drop the outer cap while an overlay is open. Either way, a test with an overlay taller than rows (asserting the status line is still the last line) would pin it.
Fixes #596.
What changes
Redraw on resize (
packages/mocactl/src/app.tsx). History printed through<Static>is wrapped at the width it was printed at, and nothing reprinted it when the width changed. The terminal then re-wrapped it on its own, which left stray and duplicated box borders. Now a width change waitsRESIZE_SETTLE_MS(100 ms) for the resize to finish and then calls the existingredraw()once. A drag that fires many resize events gets one redraw, and the first render is skipped. A height change alone doesn't reprint history, because history is wrapped by width only.Cap the live region to the window (
packages/mocactl/src/views/Chat.tsx). A streaming reply could make the live region taller than the window. Ink then clears and repaints the screen on every frame, so the input box jumped and flickered. The live region is now capped atrows - 1lines, using Ink 8'smaxHeightandoverflowY="hidden". An overlong reply is cut off at the top so its newest lines stay in view. The overlay, input box and status line never shrink. The full reply still reaches history through<Static>once it settles.Out of scope: pinning the input box to the bottom when the transcript is short. That needs a full-screen layout that replaces the print-once history design (spec §6.1), as the issue says.
Tests
test/chat.test.tsx: a 50-line streaming reply withrows=10renders in at most 9 live lines, ends with the input box's bottom border and then the status line, and shows the newest reply line.test/app.test.tsx:mountInteractivegains aresize()helper. Three resizes, each half the settle delay apart, clear nothing while they're arriving, then clear the screen exactly once after the delay and reprint the history. The test fails if the debounce'sclearTimeoutis removed.pnpm typecheckandmake lintpass, and Prettier finds nothing to change.mainwithout this change. They'rewaitFortimeouts, and the failing tests differ from run to run, so they look like timing flakes under load. The UI test files touched here (app, chat, overlays) pass when run on their own: 84/84.Checked by hand in a real terminal: resizing the window and streaming a long reply both behave correctly.
🤖 Assisted-By Claude Code