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:03:21 +0100	[thread overview]
Message-ID: <2362-1541646201.813952@nGIL.zWP_.YhaK> (raw)
In-Reply-To: <CAKc7PVDgEtfLAibbxRr36=UgPoPk8grvsH5G2+AOipr_vmt-cQ@mail.gmail.com>

Sebastian Gniazdowski wrote:
> The last test from the attached ztst reveals this. Before-last test
> overlapping colors with standard fg=green/fg=red symbols. Result is a

>  rh2() { region_highlight+=( "1 2 fg=#cc0000" ); }

It isn't overlapping colours but the += assignment that fails.

I had missed that we have code for converting attributes back to text
form and appending to region_highlight apparently relies on that.

This does also mean that if you use a short form like fg=#c00, it gets
expanded to fg=#cc0000. It also means that with nearcolor,
region_highlight reflects the converted value, fg=160 in this case.
I don't think this is a problem. There was previously forms that would
not be preserved exactly.

Thanks for testing the changes.
By the way, your tests might be easier to manage if you set
fg_start_code, fg_end_code and so on in zle_highlight to some plain text
markers. Could be clearer to follow than $'\x1b'. None of your tests
work on my system. I think the expected results reflect the particulars
of the termcap database for your terminal on your system. zle -T may
help but to be portable, the tests may also need to search for a
256color terminal and skip if none is found.

Oliver

diff --git a/Src/prompt.c b/Src/prompt.c
index 284c02475..377015ad8 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1646,7 +1646,8 @@ match_colour(const char **teststrp, int is_fg, int colour)
 		color.red = col >> 16;
 		color.green = (col & 0xff00) >> 8;
 		color.blue = col & 0xff;
-	    }
+	    } else
+		return TXT_ERROR;
 	    *teststrp = end;
 	    colour = runhookdef(GETCOLORATTR, &color) - 1;
 	    if (colour < 0) { /* no hook function added, try true color (24-bit) */
@@ -1744,11 +1745,12 @@ match_highlight(const char *teststr, zattr *on_var)
 
 /*
  * Count or output a string for colour information: used
- * by output_highlight().
+ * by output_highlight(). count when buf is NULL.
+ * returned count excludes the terminating null byte.
  */
 
 static int
-output_colour(int colour, int fg_bg, int use_tc, char *buf)
+output_colour(int colour, int fg_bg, int use_tc, int truecol, char *buf)
 {
     int atrlen = 3, len;
     char *ptr = buf;
@@ -1756,8 +1758,12 @@ output_colour(int colour, int fg_bg, int use_tc, char *buf)
 	strcpy(ptr, fg_bg == COL_SEQ_FG ? "fg=" : "bg=");
 	ptr += 3;
     }
+    if (truecol) {
+	/* length of hex triplet always 7, don't need sprintf to count */
+	atrlen += buf ? sprintf(ptr, "#%02x%02x%02x", colour >> 16,
+		(colour >> 8) & 0xff, colour & 0xff) : 7;
     /* colour should only be > 7 if using termcap but let's be safe */
-    if (use_tc || colour > 7) {
+    } else if (use_tc || colour > 7) {
 	char digbuf[DIGBUFSIZE];
 	sprintf(digbuf, "%d", colour);
 	len = strlen(digbuf);
@@ -1795,6 +1801,7 @@ output_highlight(zattr atr, char *buf)
 	len = output_colour(txtchangeget(atr, TXT_ATTR_FG_COL),
 			    COL_SEQ_FG,
 			    (atr & TXT_ATTR_FG_TERMCAP),
+			    (atr & TXT_ATTR_FG_24BIT),
 			    ptr);
 	atrlen += len;
 	if (buf)
@@ -1811,6 +1818,7 @@ output_highlight(zattr atr, char *buf)
 	len = output_colour(txtchangeget(atr, TXT_ATTR_BG_COL),
 			    COL_SEQ_BG,
 			    (atr & TXT_ATTR_BG_TERMCAP),
+			    (atr & TXT_ATTR_BG_24BIT),
 			    ptr);
 	atrlen += len;
 	if (buf)

  parent reply	other threads:[~2018-11-08  3:03 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
2018-11-08  9:25       ` Sebastian Gniazdowski
2018-11-08  3:03 ` Oliver Kiddle [this message]
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=2362-1541646201.813952@nGIL.zWP_.YhaK \
    --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).