From 1ac099f019c5a046f5eddec4eb52ac609537ce45 Mon Sep 17 00:00:00 2001 From: YoshKoz <77861115+YoshKoz@users.noreply.github.com> Date: Sun, 19 Apr 2026 22:50:01 +0200 Subject: [PATCH] fix: append ANSI reset after trimming to prevent terminal color bleed 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 --- src/util.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 3688d92c7..636a53b02 100644 --- a/src/util.rs +++ b/src/util.rs @@ -232,7 +232,14 @@ pub fn ansi_trim_end(s: &str) -> String { if trimmed_width == UnicodeWidthStr::width(stripped.as_ref()) { return s.to_string(); } - truncate(s, trimmed_width).into_owned() + // Truncating drops any ANSI reset code that was at the end of the original + // string, which leaves color/style open in the terminal. Append an explicit + // reset so every trimmed line always ends in a clean state. + let mut result = truncate(s, trimmed_width).into_owned(); + if stripped.as_ref() != s { + result.push_str("\x1b[0m"); + } + result } pub fn find_column_kind(pat: &str) -> Option {