#12913: TUI: truncate lines to fit terminal width on narrow terminals
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
#5509: Fix TUI crash when terminal window is too narrow
by omar-khaled-2 · 2026-01-31
85.5%
#17677: fix(tui): prevent crash when rendered line exceeds terminal width
by Phineas1500 · 2026-02-16
84.9%
#6260: fix(tui): prevent width overflow crashes from nested ANSI escape codes
by 0xktn · 2026-02-01
83.8%
#4035: fix(tui): ensure UI updates when status changes
by willerxar-cmyk · 2026-01-29
77.2%
#6502: fix(tui): skip empty text for tool-only assistant turns
by douvy · 2026-02-01
74.6%
#18942: fix(tui): trigger render after finalizing chat assistant message
by BinHPdev · 2026-02-17
74.3%
#6819: fix(tui): handle unstructured tool results and errors in tool execu...
by TreyDong · 2026-02-02
73.0%
#9220: Fix: TUI drops API responses silently when runID already finalized
by vishaltandale00 · 2026-02-05
73.0%
#17777: fix(tui): prevent URL breaking during line wrap
by proto-genesys-x · 2026-02-16
72.5%
#12974: fix: intermittent (no output) reported by users
by vincentkoc · 2026-02-10
72.4%