set_color: don't set color to black before resetting attributes

I was surprised to see:

> set_color normal | string escape
\e\[30m\e\(B\e\[m

I only expected to see a sgr0 here.

Cleanup a nearby `else { if (...) {` and comment with a bogus example.
This commit is contained in:
Aaron Gyes
2019-01-22 21:44:30 -08:00
parent a17e6fa4e8
commit 09d0f7741d

View File

@@ -216,21 +216,18 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
}
if (bgcolor != NULL && bg.is_normal()) {
write_color(rgb_color_t::black(), false /* not is_fg */);
writembs_nofail(tparm((char *)exit_attribute_mode));
}
if (!fg.is_none()) {
if (fg.is_normal() || fg.is_reset()) {
write_color(rgb_color_t::black(), true /* is_fg */);
writembs_nofail(tparm((char *)exit_attribute_mode));
} else {
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());
}
} else if (!write_color(fg, true /* is_fg */)) {
// We need to do *something* or the lack of any output
// with a cartesian product here would make "foo" disappear
// on lame terminals:
// $ env TERM=vt100 fish -c 'echo (set_color red)"foo"'
set_color(rgb_color_t::reset(), rgb_color_t::none());
}
}