zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh hackers list <zsh-workers@zsh.org>
Cc: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Subject: Re: [BUG?] If true-color is used, overlapping colors do not work
Date: Thu, 08 Nov 2018 04:48:24 +0100	[thread overview]
Message-ID: <2917-1541648904.343056@V1WL.VCjm.HHYZ> (raw)
In-Reply-To: <CAKc7PVApxGVqo8pcMsrHMjbV4-p1Z31XPg4vOjLMSWEAJLhYxQ@mail.gmail.com>

Sebastian Gniazdowski wrote:
> I was testing on Linux, via docker. $termcap[Co] shows 8, the same
> $terminfo[colors]. The zsh/nearcolor fails and maybe it could fail a
> little better?

I admit that black, as opposed to the default colour isn't clever. The
patch changes this.

> Color 30 is apparently black. Maybe zsh/nearcolor could use (compare
> against) first 8 or 16 colors when $termcap[Co] <= 8?

The first 16 colours vary between terminals and are also commonly
configurable so nearcolor never compares against them. 

There is an escape sequence for getting colour definitions but I don't
think trying to use it gains us much.

Oliver


diff --git a/Src/Modules/nearcolor.c b/Src/Modules/nearcolor.c
index 128658e20..7ebc75365 100644
--- a/Src/Modules/nearcolor.c
+++ b/Src/Modules/nearcolor.c
@@ -117,13 +117,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);

  reply	other threads:[~2018-11-08  3:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07 13:19 Sebastian Gniazdowski
2018-11-07 14:40 ` Sebastian Gniazdowski
2018-11-07 19:19   ` Sebastian Gniazdowski
2018-11-08  3:48     ` Oliver Kiddle [this message]
2018-11-08  9:25       ` Sebastian Gniazdowski
2018-11-08  3:03 ` Oliver Kiddle
2018-11-08  9:19   ` Sebastian Gniazdowski
2018-11-09  1:28     ` Oliver Kiddle
2018-11-09 15:39       ` Sebastian Gniazdowski
2018-11-11  0:43       ` Sebastian Gniazdowski
2018-11-11  5:11         ` Sebastian Gniazdowski
2018-11-24 17:32         ` highlight test cases (was Re: [BUG?] If true-color is used, overlapping colors do not work) Oliver Kiddle
2018-11-30  0:34           ` Sebastian Gniazdowski
2018-12-07  1:55             ` [BUG] General 256 colors bug – zle_highlight / fg_start_code, etc. is not respected (was: highlight test cases) Sebastian Gniazdowski
2018-12-07 20:26               ` Sebastian Gniazdowski
2018-12-09 19:13                 ` Daniel Shahaf
2018-12-11  8:06                   ` Sebastian Gniazdowski
2018-12-10  2:54             ` highlight test cases (was Re: [BUG?] If true-color is used, overlapping colors do not work) Oliver Kiddle
2018-12-10 23:51               ` Sebastian Gniazdowski
2018-12-10 23:54                 ` Sebastian Gniazdowski
2018-11-11  5:38       ` X04 zle highlight tests, near-color bug Sebastian Gniazdowski
2018-11-18 15:34         ` Sebastian Gniazdowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2917-1541648904.343056@V1WL.VCjm.HHYZ \
    --to=okiddle@yahoo.co.uk \
    --cc=sgniazdowski@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).