Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG?] If true-color is used, overlapping colors do not work



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)



Messages sorted by: Reverse Date, Date, Thread, Author