From 4762d52e52f37c2e1a12575dd297dc27eeff6670 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 9 Mar 2021 13:16:40 +0100 Subject: [PATCH] output: A background is set if it's not a special non-color For reasons unclear to me, fish enables bold mode unconditionally if the background is set. However, this called a background "set" if it wasn't exactly the "normal" color, whereas set_color --print-colors would set a color of *none*. We have three special non-color colors: - "normal" - "reset" - "none" All of these specify some form of absence of background color, so all of them should be checked. Fixes #7805 --- src/output.cpp | 6 ++++-- tests/pexpects/set_color.py | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 5dde264bc..da125840c 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -179,12 +179,14 @@ void outputter_t::set_color(rgb_color_t fg, rgb_color_t bg) { reset_modes(); } - if (!last_color2.is_normal() && !last_color2.is_reset()) { + if (!last_color2.is_special()) { // Background was set. + // "Special" here refers to the special "normal", "reset" and "none" colors, + // that really jus disable the background. last_bg_set = true; } - if (!bg.is_normal()) { + if (!bg.is_special()) { // Background is set. bg_set = true; if (fg == bg) fg = (bg == rgb_color_t::white()) ? rgb_color_t::black() : rgb_color_t::white(); diff --git a/tests/pexpects/set_color.py b/tests/pexpects/set_color.py index 50897f660..b645f9090 100644 --- a/tests/pexpects/set_color.py +++ b/tests/pexpects/set_color.py @@ -35,9 +35,10 @@ expect_str("bryellow") expect_str("cyan") expect_str("green") expect_str("magenta") -expect_str("\x1b[31mred") -expect_str("\x1b[37mwhite") -expect_str("\x1b[33myellow") +# These should be anchored at the beginning of the line, no e.g. bold sequence before. +expect_str("\n\x1b[31mred") +expect_str("\n\x1b[37mwhite") +expect_str("\n\x1b[33myellow") expect_str("normal") expect_prompt()