Fix ANSI wrapping stack overflow

closes #5185
This commit is contained in:
Mario Zechner
2026-05-30 01:02:48 +02:00
parent 31b961f2ac
commit 9c4a3f3518
2 changed files with 11 additions and 2 deletions

View File

@@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Fixed ANSI text wrapping to avoid stack overflows on very long wrapped lines ([#5185](https://github.com/earendil-works/pi/issues/5185)).
## [0.77.0] - 2026-05-28
### Fixed

View File

@@ -670,7 +670,10 @@ export function wrapTextWithAnsi(text: string, width: number): string[] {
for (const inputLine of inputLines) {
// Prepend active ANSI codes from previous lines (except for first line)
const prefix = result.length > 0 ? tracker.getActiveCodes() : "";
result.push(...wrapSingleLine(prefix + inputLine, width));
const wrappedLines = wrapSingleLine(prefix + inputLine, width);
for (const wrappedLine of wrappedLines) {
result.push(wrappedLine);
}
// Update tracker with codes from this line for next iteration
updateTrackerFromText(inputLine, tracker);
}
@@ -714,7 +717,9 @@ function wrapSingleLine(line: string, width: number): string[] {
// Break long token - breakLongWord handles its own resets
const broken = breakLongWord(token, width, tracker);
wrapped.push(...broken.slice(0, -1));
for (let i = 0; i < broken.length - 1; i++) {
wrapped.push(broken[i]!);
}
currentLine = broken[broken.length - 1];
currentVisibleLength = visibleWidth(currentLine);
continue;