mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 11:02:17 +00:00
Fix ANSI styles not preserved across newlines in text wrapping
wrapTextWithAnsi() was processing each line independently after splitting on newlines, losing ANSI state. When styled text contained embedded newlines (e.g. from markdown paragraphs), subsequent lines would lose their styling. Fixed by tracking ANSI state across lines and prepending active codes to lines after the first. Fixes #197
This commit is contained in:
parent
fbda78bfb3
commit
ce9ffaff91
1 changed files with 7 additions and 1 deletions
|
|
@ -312,11 +312,17 @@ export function wrapTextWithAnsi(text: string, width: number): string[] {
|
|||
}
|
||||
|
||||
// Handle newlines by processing each line separately
|
||||
// Track ANSI state across lines so styles carry over after literal newlines
|
||||
const inputLines = text.split("\n");
|
||||
const result: string[] = [];
|
||||
const tracker = new AnsiCodeTracker();
|
||||
|
||||
for (const inputLine of inputLines) {
|
||||
result.push(...wrapSingleLine(inputLine, width));
|
||||
// Prepend active ANSI codes from previous lines (except for first line)
|
||||
const prefix = result.length > 0 ? tracker.getActiveCodes() : "";
|
||||
result.push(...wrapSingleLine(prefix + inputLine, width));
|
||||
// Update tracker with codes from this line for next iteration
|
||||
updateTrackerFromText(inputLine, tracker);
|
||||
}
|
||||
|
||||
return result.length > 0 ? result : [""];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue