← Back to PRs

#12913: TUI: truncate lines to fit terminal width on narrow terminals

by kutayilmaaz open 2026-02-09 22:28 View on GitHub →
stale
Fixes #12890 ## Problem TUI crashed with "Rendered line exceeds terminal width" error when terminal width was narrower than content (e.g., 120 columns). ## Solution Added line truncation to prevent content from exceeding terminal width: - ChatLog.addSystem() now truncates system messages - ChatLog initialized with process.stdout.columns on startup - Header and footer text truncated before rendering - Uses visibleWidth() and truncateToWidth() from @mariozechner/pi-tui ## Testing ✅ All 72 TUI tests pass ✅ Follows existing pattern in searchable-select-list.ts ✅ Tested with narrow terminal (120 columns) ## Notes - AI-assisted with GitHub Copilot - Fully tested <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR prevents pi-tui from throwing "Rendered line exceeds terminal width" by truncating text before rendering in a few high-traffic surfaces: system messages (`ChatLog.addSystem()`), the dynamic header, and the footer. It also initializes `ChatLog` with the current terminal width (via `process.stdout.columns`) so truncation is based on the user’s terminal. These changes fit into the existing TUI rendering model where `Text` nodes are updated frequently and must never exceed the terminal width enforced by `@mariozechner/pi-tui`. <h3>Confidence Score: 3/5</h3> - Mostly safe, but still fails on very narrow terminals due to width clamping issues. - Truncation is added in the right places, but the new width calculations can still produce widths that exceed the terminal (ChatLog minimum 50) or invalid widths (negative/zero maxWidth for header/footer), which can reintroduce the original crash scenario on narrow terminals. - src/tui/components/chat-log.ts, src/tui/tui.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs