From 0de5bbd13e64e22bb1984d92e33017f157755bf0 Mon Sep 17 00:00:00 2001 From: phranck Date: Wed, 28 Jan 2026 21:22:28 +0100 Subject: [PATCH] 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. --- Sources/TUIKit/App/App.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sources/TUIKit/App/App.swift b/Sources/TUIKit/App/App.swift index c3f5a88..404b664 100644 --- a/Sources/TUIKit/App/App.swift +++ b/Sources/TUIKit/App/App.swift @@ -555,7 +555,10 @@ internal final class AppRunner { 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..