From 09d0f7741d61a26571d077cb448238a5fd05e97c Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Tue, 22 Jan 2019 21:44:30 -0800 Subject: [PATCH] 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. --- src/builtin_set_color.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/builtin_set_color.cpp b/src/builtin_set_color.cpp index f1b11efe4..ae81acbd5 100644 --- a/src/builtin_set_color.cpp +++ b/src/builtin_set_color.cpp @@ -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()); } }