From 692e6d57cfdbf7937bfb1c31f0bb9a5da76434ce Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 9 Dec 2025 09:34:27 +0100 Subject: [PATCH] fish_indent --ansi to emit SGR0 before final newline Buggy programs parsing "fish_indent --ansi" output break because we wemit SGR0 after the final newline. I suppose this is weird, and there's no need to wait until after the \n to emit SGR0 so let's move it before that. Closes #12096 --- src/highlight/highlight.rs | 3 +++ tests/checks/indent.fish | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/highlight/highlight.rs b/src/highlight/highlight.rs index eac7ba676..607420847 100644 --- a/src/highlight/highlight.rs +++ b/src/highlight/highlight.rs @@ -76,6 +76,9 @@ pub fn colorize(text: &wstr, colors: &[HighlightSpec], vars: &dyn Environment) - outp.set_text_face(face); last_color = color; } + if i + 1 == text.char_count() && c == '\n' { + outp.set_text_face(TextFace::default()); + } outp.writech(c); } outp.set_text_face(TextFace::default()); diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index c3afa9986..ff8dd09da 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -494,6 +494,12 @@ echo $status #CHECK: 0 echo 'PATH={$PATH[echo " "' | $fish_indent --ansi # CHECK: PATH={$PATH[echo " " +fish_config theme choose "ayu Dark" +echo -n 'echo hello' | builtin fish_indent --ansi +echo end +# CHECK: {{\x1b\[38;2;57;186;230mecho\x1b\[38;2;179;177;173m hello\x1b\[38;2;242;150;104m\x1b\[m}} +# CHECK: end + echo a\> | $fish_indent # CHECK: a >