fix(pi-tui): prevent crashes on very narrow terminals - #1303
Merged
Conversation
🦋 Changeset detectedLatest commit: 9fb9da7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
Merged
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.
Related Issue
No open issue for this crash. Related prior fix: #240 covered a narrow-terminal crash in the session picker; this PR fixes the remaining narrow-terminal crashes in the editor and the renderer core. The problem is explained below.
Problem
When the terminal is resized to a very narrow width (roughly ≤ 7 columns) while the input editor contains CJK or emoji text, the TUI crashes and the process exits. This is close to always reproducible for CJK users.
Root causes in the vendored
packages/pi-tui:terminal.columnsdown the component tree with no lower bound, and several components callrepeat()with widths that can go negative.Narrow-width fixes existed once on an unmerged branch as a pnpm patch and were lost when pi-tui was re-vendored, so this PR also adds guard rails against losing them again.
What changed
Following the "never crash, degrade gracefully" approach (clamp + truncate instead of throw):
Container.renderclamps the incoming width to ≥ 1, so no component ever sees a non-positive width from the render tree.repeat()guards for blank-line padding, markdown horizontal rules, and the editor's top/bottom borders.packages/pi-tui/AGENTS.md: documents each local divergence from upstream with its guarding tests, so future re-vendoring keeps these fixes.Verification: pi-tui suite 709/709 passing plus a clean typecheck; full repo vitest run 9112 passed, 0 failed.
Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.