commit 5dda212b3be3f1f12ad31e3d6543d367f987ee55 Author: Sebastian Gniazdowski Date: Sat Dec 8 22:42:49 2018 +0100 Instead of using termcap, 256-colours are based on zle_highlight entries Following code snippet performs the conversion of colour number to the code to be emitted to terminal (the example shows foreground color handling): ... strcpy(colseq_buf, fg_bg_sequences[fg_bg].start); ... } else if (colour > 7 && colour <= 255) { ptr += sprintf(ptr, "8;5;%d", colour); ... diff --git a/Src/prompt.c b/Src/prompt.c index 568bfc2a9..4a90f5fcf 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -1764,7 +1764,9 @@ output_colour(int colour, int fg_bg, int use_tc, int truecol, char *buf) /* 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 */ + /* colour should only be > 7 if using termcap but let's be safe + * update: currently other places in code don't always imply + * that colour > 7 => using-termcap */ } else if (use_tc || colour > 7) { char digbuf[DIGBUFSIZE]; sprintf(digbuf, "%d", colour); @@ -2020,7 +2022,7 @@ set_colour_attribute(zattr atr, int fg_bg, int flags) * highlighting variables, so much of this shouldn't be * necessary at this point, but we might as well be safe. */ - if (!def && !use_truecolor && (colour > 7 || use_termcap)) { + if (!def && !use_truecolor && (colour > 255 && use_termcap)) { /* * We can if it's available, and either we couldn't get * the maximum number of colours, or the colour is in range. @@ -2046,9 +2048,10 @@ set_colour_attribute(zattr atr, int fg_bg, int flags) } /* * Nope, that didn't work. - * If 0 to 7, assume standard ANSI works, otherwise it won't. + * If 0 to 7, assume standard ANSI works, if 8 to 255, assume + * standard 256-color escapes works, otherwise it won't. */ - if (colour > 7) + if (colour > 255) return; } @@ -2067,6 +2070,8 @@ set_colour_attribute(zattr atr, int fg_bg, int flags) } else if (use_truecolor) { ptr += sprintf(ptr, "8;2;%d;%d;%d", colour >> 16, (colour >> 8) & 0xff, colour & 0xff); + } else if (colour > 7 && colour <= 255) { + ptr += sprintf(ptr, "8;5;%d", colour); } else *ptr++ = colour + '0'; strcpy(ptr, fg_bg_sequences[fg_bg].end);