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.
This commit is contained in:
can1357
2026-02-06 05:35:56 +01:00
parent 4dfeebe36a
commit 1849d51458
2 changed files with 14 additions and 1 deletions
+2
View File
@@ -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 <session-id>`)
@@ -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
+12 -1
View File
@@ -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}`);