Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG?] If true-color is used, overlapping colors do not work
- X-seq: zsh-workers 43804
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [BUG?] If true-color is used, overlapping colors do not work
- Date: Thu, 08 Nov 2018 04:03:21 +0100
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Cc: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1541646205; bh=g2yLGN78Bd85UXHlCRxWBtW3y5owZ2zfVB2oTHBjub4=; h=To:From:References:Subject:Date:From:Subject; b=qM8EDmadK+9gQkL68GrxS+D7S9DZGEtUNZEiNQas+2Q8lZTxE8XupvpKzoS32+JaQx9gE8tkjqbA7XC3N7xk8WbeFEe1sjxfOVYIPFLZg8fNzclXR5UHWz7uG2xSiE0baKs1VW/DNI0jwduTB8FlqXqtDcGbZ6fMkAcmlbHkla9bWYC+54QuRLTJOJMBccaNHYP4BMckXhTsb2ubJ+MDDZNMX9FKu8fNaJ5xIMCHuJ8v7FnyvGFmJqOhbZawMla4sJDbUBysB0Xy1Fk60eDkaNS2DBhtZe1EVMmJpLcOzYwUTQ3o8Fdv7s3l0TzbnBQ95TLN7fHXn8QY9TTsyT1Lcw==
- In-reply-to: <CAKc7PVDgEtfLAibbxRr36=UgPoPk8grvsH5G2+AOipr_vmt-cQ@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <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)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author