mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 00:47:30 +00:00
Stop swallowing the cartesian product
This should work: > env TERM=vt100 ./fish -c 'echo (set_color red)"hi"' We do a ::reset() if setting the color doesn't happen. Fixes #2951
This commit is contained in:
parent
644ea82c2f
commit
5afd939f3e
3 changed files with 10 additions and 4 deletions
|
@ -179,7 +179,12 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
write_color(rgb_color_t::black(), true /* is_fg */);
|
write_color(rgb_color_t::black(), true /* is_fg */);
|
||||||
writembs(tparm(exit_attribute_mode));
|
writembs(tparm(exit_attribute_mode));
|
||||||
} else {
|
} else {
|
||||||
write_color(fg, true /* is_fg */);
|
if (!write_color(fg, true /* is_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
|
||||||
|
set_color(rgb_color_t::reset(), rgb_color_t::none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,12 +106,12 @@ static bool write_background_color(unsigned char idx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exported for builtin_set_color's usage only.
|
// Exported for builtin_set_color's usage only.
|
||||||
void write_color(rgb_color_t color, bool is_fg) {
|
bool write_color(rgb_color_t color, bool is_fg) {
|
||||||
bool supports_term24bit = !!(output_get_color_support() & color_support_term24bit);
|
bool supports_term24bit = !!(output_get_color_support() & color_support_term24bit);
|
||||||
if (!supports_term24bit || !color.is_rgb()) {
|
if (!supports_term24bit || !color.is_rgb()) {
|
||||||
// Indexed or non-24 bit color.
|
// Indexed or non-24 bit color.
|
||||||
unsigned char idx = index_for_color(color);
|
unsigned char idx = index_for_color(color);
|
||||||
(is_fg ? write_foreground_color : write_background_color)(idx);
|
return (is_fg ? write_foreground_color : write_background_color)(idx);
|
||||||
} else {
|
} else {
|
||||||
// 24 bit! No tparm here, just ANSI escape sequences.
|
// 24 bit! No tparm here, just ANSI escape sequences.
|
||||||
// Foreground: ^[38;2;<r>;<g>;<b>m
|
// Foreground: ^[38;2;<r>;<g>;<b>m
|
||||||
|
@ -127,6 +127,7 @@ void write_color(rgb_color_t color, bool is_fg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the fg and bg color. May be called as often as you like, since if the new color is the same
|
/// Sets the fg and bg color. May be called as often as you like, since if the new color is the same
|
||||||
|
|
|
@ -51,7 +51,7 @@ void output_set_color_support(color_support_t support);
|
||||||
|
|
||||||
rgb_color_t best_color(const std::vector<rgb_color_t> &colors, color_support_t support);
|
rgb_color_t best_color(const std::vector<rgb_color_t> &colors, color_support_t support);
|
||||||
|
|
||||||
void write_color(rgb_color_t color, bool is_fg);
|
bool write_color(rgb_color_t color, bool is_fg);
|
||||||
unsigned char index_for_color(rgb_color_t c);
|
unsigned char index_for_color(rgb_color_t c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue