fix: append ANSI reset after trimming to prevent terminal color bleed#908
Closed
YoshKoz wants to merge 1 commit intodalance:masterfrom
Closed
fix: append ANSI reset after trimming to prevent terminal color bleed#908YoshKoz wants to merge 1 commit intodalance:masterfrom
YoshKoz wants to merge 1 commit intodalance:masterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #778
Root Cause
ansi_trim_end()detects trailing whitespace in colored output by stripping ANSI codes, measuring the trimmed visual width, then callingtruncate(s, trimmed_width)to remove the trailing spaces from the ANSI-wrapped string.truncate()stops at the first character that would exceedtrimmed_widthand returns everything up to that point — discarding any ANSI escape sequences that appeared after it, including the\x1b[0mreset 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[0mreset when the input contained ANSI codes (detected by comparingstripped != s). This ensures every trimmed line ends in a clean terminal state without affecting plain-text output paths.Verified by piping
procs --color=alwaysthroughcat -A: each row now ends with\x1b[0mbefore the newline.