fix: Preserve background color after ANSI reset codes

Replace all reset codes in rendered content with 'reset + restore background'
to ensure the theme background persists after styled text ends.

This fixes the issue where text with ANSI formatting would reset the
background color, leaving parts of the terminal with the wrong background.
This commit is contained in:
phranck
2026-01-28 21:22:28 +01:00
parent 497ce9cb56
commit 0de5bbd13e
+11 -5
View File
@@ -555,7 +555,10 @@ internal final class AppRunner<A: App> {
let visibleWidth = line.strippedLength
let padding = max(0, terminalWidth - visibleWidth)
let paddedLine = bgCode + line + String(repeating: " ", count: padding) + reset
// Replace all reset codes with "reset + restore background"
let lineWithBg = line.replacingOccurrences(of: reset, with: reset + bgCode)
let paddedLine = bgCode + lineWithBg + String(repeating: " ", count: padding) + reset
terminal.write(paddedLine)
}
}
@@ -643,7 +646,7 @@ extension WindowGroup: SceneRenderable {
let bgCode = ANSIRenderer.backgroundCode(for: bgColor)
let reset = ANSIRenderer.reset
// Write buffer to terminal, wrapping each line with background color
// Write buffer to terminal, ensuring consistent background color
for row in 0..<terminalHeight {
terminal.moveCursor(toRow: 1 + row, column: 1)
@@ -652,9 +655,12 @@ extension WindowGroup: SceneRenderable {
let visibleWidth = line.strippedLength
let padding = max(0, terminalWidth - visibleWidth)
// Wrap entire line with background: bg + content + padding + reset
// The bgCode sets the background for everything that follows
let paddedLine = bgCode + line + String(repeating: " ", count: padding) + reset
// Replace all reset codes with "reset + restore background"
// This ensures background color persists after styled text
let lineWithBg = line.replacingOccurrences(of: reset, with: reset + bgCode)
// Wrap entire line with background
let paddedLine = bgCode + lineWithBg + String(repeating: " ", count: padding) + reset
terminal.write(paddedLine)
} else {
// Empty row - fill with background color