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
This commit is contained in:
Johannes Altmanninger
2025-12-09 09:34:27 +01:00
parent 7952545460
commit 692e6d57cf
2 changed files with 9 additions and 0 deletions

View File

@@ -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());

View File

@@ -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 >