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) {