From 5a7070178826e7b0db94e0a3d285849315e5c5ab Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 8 Nov 2018 11:01:36 +0100 Subject: 43805: make nearcolor module use the default colour rather than black as a fallback --- ChangeLog | 3 +++ Src/Modules/nearcolor.c | 7 ++++--- Src/prompt.c | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 636ea4dd7..41a2f7aa9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2018-11-08 Oliver Kiddle + * 43805: Src/Modules/nearcolor.c, Src/prompt.c: make nearcolor + module use the default colour rather than black as a fallback + * 43804: Src/prompt.c: also need to be able to turn colour attributes back into hex triples for region_highlight variable diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c index b51b4fd2c..0b9877bf4 100644 --- a/Src/Modules/nearcolor.c +++ b/Src/Modules/nearcolor.c @@ -146,13 +146,14 @@ mapRGBto256(int red, int green, int blue) static int getnearestcolor(UNUSED(Hookdef dummy), Color_rgb col) { + /* we add 1 to the colours so that colour 0 (black) is + * distinguished from runhookdef() indicating that no + * hook function is registered */ if (tccolours == 256) return mapRGBto256(col->red, col->green, col->blue) + 1; if (tccolours == 88) return mapRGBto88(col->red, col->green, col->blue) + 1; - /* returning 1 indicates black rather than failure (0) so this - * module still serves to prevent fallback on true color */ - return 1; + return -1; } static struct features module_features = { diff --git a/Src/prompt.c b/Src/prompt.c index 377015ad8..568bfc2a9 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -1650,10 +1650,12 @@ match_colour(const char **teststrp, int is_fg, int colour) return TXT_ERROR; *teststrp = end; colour = runhookdef(GETCOLORATTR, &color) - 1; - if (colour < 0) { /* no hook function added, try true color (24-bit) */ + if (colour == -1) { /* no hook function added, try true color (24-bit) */ colour = (((color.red << 8) + color.green) << 8) + color.blue; return on | (is_fg ? TXT_ATTR_FG_24BIT : TXT_ATTR_BG_24BIT) | (zattr)colour << shft; + } else if (colour <= -2) { + return TXT_ERROR; } } else if ((named = ialpha(**teststrp))) { colour = match_named_colour(teststrp); -- cgit 1.4.1