From f0c5d86d20f85bbeee957b0e9b06ee085ea40c80 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 18 Aug 2026 16:49:14 +0200 Subject: [PATCH] fix(tui): fit text padding to narrow widths, closes #8252 --- packages/tui/CHANGELOG.md | 1 + packages/tui/src/components/text.ts | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index 6c0416351..33dfa5812 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed duplicate fullscreen right-click paste in VS Code-based terminals on Windows ([#8186](https://github.com/earendil-works/pi/issues/8186)). +- Fixed padded text exceeding narrow terminal widths ([#8252](https://github.com/earendil-works/pi/issues/8252)). ## [0.84.2] - 2026-08-14 diff --git a/packages/tui/src/components/text.ts b/packages/tui/src/components/text.ts index 3809a48a8..7a50e2721 100644 --- a/packages/tui/src/components/text.ts +++ b/packages/tui/src/components/text.ts @@ -60,15 +60,16 @@ export class Text implements Component { // Replace tabs with 3 spaces const normalizedText = this.text.replace(/\t/g, " "); - // Calculate content width (subtract left/right margins) - const contentWidth = Math.max(1, width - this.paddingX * 2); + // Reduce margins when necessary so content and padding fit within the available width. + const paddingX = Math.min(this.paddingX, Math.max(0, Math.floor((width - 1) / 2))); + const contentWidth = Math.max(1, width - paddingX * 2); // Wrap text (this preserves ANSI codes but does NOT pad) const wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth); // Add margins and background to each line - const leftMargin = " ".repeat(this.paddingX); - const rightMargin = " ".repeat(this.paddingX); + const leftMargin = " ".repeat(paddingX); + const rightMargin = " ".repeat(paddingX); const contentLines: string[] = []; for (const line of wrappedLines) {