Skip to content

fix: append ANSI reset after trimming to prevent terminal color bleed#908

Closed
YoshKoz wants to merge 1 commit intodalance:masterfrom
YoshKoz:fix/ansi-reset-after-trim
Closed

fix: append ANSI reset after trimming to prevent terminal color bleed#908
YoshKoz wants to merge 1 commit intodalance:masterfrom
YoshKoz:fix/ansi-reset-after-trim

Conversation

@YoshKoz
Copy link
Copy Markdown

@YoshKoz YoshKoz commented Apr 19, 2026

Fixes #778

Root Cause

ansi_trim_end() detects trailing whitespace in colored output by stripping ANSI codes, measuring the trimmed visual width, then calling truncate(s, trimmed_width) to remove the trailing spaces from the ANSI-wrapped string.

truncate() stops at the first character that would exceed trimmed_width and returns everything up to that point — discarding any ANSI escape sequences that appeared after it, including the \x1b[0m reset code at the end of the last styled column.

Result: when the last visible column has trailing padding (content shorter than column width), the reset code is dropped, leaving the terminal in a styled state (bold/white) after procs exits.

Fix

After truncation, append an explicit \x1b[0m reset when the input contained ANSI codes (detected by comparing stripped != s). This ensures every trimmed line ends in a clean terminal state without affecting plain-text output paths.

Before: \x1b[38;5;15mCommand\n         (color/bold left open)
After:  \x1b[38;5;15mCommand\x1b[0m\n  (properly reset)

Verified by piping procs --color=always through cat -A: each row now ends with \x1b[0m before the newline.

ansi_trim_end() calls truncate() to strip trailing whitespace from
colored output. truncate() stops at the last visible character and
discards everything after, including the \x1b[0m reset code that was
at the end of the original styled string.

When the last visible column has trailing padding, the reset code is
dropped, leaving the terminal in a styled state (bold/white) after
procs exits. Adding an explicit reset after truncation ensures each
trimmed line closes any open ANSI codes.

Only appended when the input contained ANSI codes (stripped != s),
so plain-text output paths are unaffected.

Fixes #778

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@YoshKoz YoshKoz closed this by deleting the head repository Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Font style not reset at the end of execution

1 participant