From 1849d514586b29f341ef7da2bbed4a1f13969840 Mon Sep 17 00:00:00 2001 From: can1357 Date: Fri, 6 Feb 2026 05:35:56 +0100 Subject: [PATCH] fix(coding-agent/tui): fixed background color stability in output blocks with SGR reset sequences - Fixed background color stability in output blocks when inner content contains SGR reset sequences, preventing background color from being cleared mid-line. --- packages/coding-agent/CHANGELOG.md | 2 ++ packages/coding-agent/src/tui/output-block.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 494586f2f..8ab7cc48b 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] + ### Added - Added resumption hint printed to stderr on session exit showing command to resume the session (e.g., `Resume this session with claude --resume `) @@ -78,6 +79,7 @@ ### Fixed +- Fixed background color stability in output blocks when inner content contains SGR reset sequences, preventing background color from being cleared mid-line - Fixed spurious ellipsis appended to output lines that were already padded to terminal width by trimming trailing spaces before truncation check - Fixed config file parsing to properly handle missing files instead of treating them as errors - Fixed truncation indicator in truncate tool to use ellipsis character (…) instead of verbose '[truncated]' suffix diff --git a/packages/coding-agent/src/tui/output-block.ts b/packages/coding-agent/src/tui/output-block.ts index 454e8937f..ab98bd118 100644 --- a/packages/coding-agent/src/tui/output-block.ts +++ b/packages/coding-agent/src/tui/output-block.ts @@ -32,7 +32,18 @@ export function renderOutputBlock(options: OutputBlockOptions, theme: Theme): st ? "accent" : "dim"; const border = (text: string) => theme.fg(borderColor, text); - const bgFn = state && applyBg ? (text: string) => theme.bg(getStateBgColor(state), text) : undefined; + const bgFn = (() => { + if (!state || !applyBg) return undefined; + const bgAnsi = theme.getBgAnsi(getStateBgColor(state)); + // Keep block background stable even if inner content contains SGR resets (e.g. "\x1b[0m"), + // which would otherwise clear the outer background mid-line. + return (text: string) => { + const stabilized = text + .replace(/\x1b\[(?:0)?m/g, m => `${m}${bgAnsi}`) + .replace(/\x1b\[49m/g, m => `${m}${bgAnsi}`); + return `${bgAnsi}${stabilized}\x1b[49m`; + }; + })(); const buildBarLine = (leftChar: string, rightChar: string, label?: string, meta?: string): string => { const left = border(`${leftChar}${cap}`);