fix(tui): fit text padding to narrow widths, closes #8252

This commit is contained in:
Mario Zechner 2026-08-18 16:49:14 +02:00
parent c061328981
commit f0c5d86d20
2 changed files with 6 additions and 4 deletions

View file

@ -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

View file

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