mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-03 06:31:12 -03:00
builtin set_color: do print other colors if one is reset-all
Commit cebc05f6c1 (Reset is not a color, 2025-04-15) tried to simpilfy
this behavior but forgot about cases like "set_color --background=normal
red --bold" where we do want to continue after resetting background.
Closes #11417
This commit is contained in:
@@ -150,30 +150,32 @@ pub fn set_color(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -
|
||||
// reset all colors/attributes. Same if foreground is "reset" (undocumented).
|
||||
if is_reset || [fg, bg].iter().any(|c| c.is_some_and(|c| c.is_normal())) {
|
||||
outp.reset_text_face();
|
||||
} else {
|
||||
// Historically we have not used set_text_face() for colors here.
|
||||
// Doing so would add two magic behaviors:
|
||||
// - if fg and bg are equal, it makes one of them white
|
||||
// - if bg is not normal, it makes the foreground bold
|
||||
// The first one seems fine but the second one not really.
|
||||
outp.set_text_face(TextFace::new(Color::None, Color::None, Color::None, style));
|
||||
if let Some(fg) = fg {
|
||||
if !outp.write_color(Paintable::Foreground, fg) {
|
||||
// We need to do *something* or the lack of any output messes up
|
||||
// when the cartesian product here would make "foo" disappear:
|
||||
// $ echo (set_color foo)bar
|
||||
outp.reset_text_face();
|
||||
}
|
||||
}
|
||||
|
||||
// Historically we have not used set_text_face() for colors here.
|
||||
// Doing so would add two magic behaviors:
|
||||
// - if fg and bg are equal, it makes one of them white
|
||||
// - if bg is not normal, it makes the foreground bold
|
||||
// The first one seems fine but the second one not really.
|
||||
outp.set_text_face(TextFace::new(Color::None, Color::None, Color::None, style));
|
||||
if let Some(fg) = fg {
|
||||
if !fg.is_normal() && !outp.write_color(Paintable::Foreground, fg) {
|
||||
// We need to do *something* or the lack of any output messes up
|
||||
// when the cartesian product here would make "foo" disappear:
|
||||
// $ echo (set_color foo)bar
|
||||
outp.reset_text_face();
|
||||
}
|
||||
if let Some(bg) = bg {
|
||||
}
|
||||
if let Some(bg) = bg {
|
||||
if !bg.is_normal() {
|
||||
outp.write_color(Paintable::Background, bg);
|
||||
}
|
||||
if let Some(underline_color) = underline_color {
|
||||
if underline_color.is_normal() {
|
||||
outp.write_command(DefaultUnderlineColor);
|
||||
} else {
|
||||
outp.write_color(Paintable::Underline, underline_color);
|
||||
}
|
||||
}
|
||||
if let Some(underline_color) = underline_color {
|
||||
if underline_color.is_normal() {
|
||||
outp.write_command(DefaultUnderlineColor);
|
||||
} else {
|
||||
outp.write_color(Paintable::Underline, underline_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ string escape (set_color --background=reset)
|
||||
# CHECKERR: set_color: Unknown color 'reset'
|
||||
|
||||
string escape (set_color --bold red --background=normal)
|
||||
# CHECK: \e\[m
|
||||
# CHECK: \e\[m\e\[1m\e\[31m
|
||||
string escape (set_color --bold red --background=blue)
|
||||
# CHECK: \e\[1m\e\[31m\e\[44m
|
||||
|
||||
|
||||
Reference in New Issue
Block a user