From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id d0d8b167 for ; Wed, 23 Jan 2019 00:06:50 +0000 (UTC) Received: (qmail 9028 invoked by alias); 23 Jan 2019 00:06:32 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44011 Received: (qmail 9112 invoked by uid 1010); 23 Jan 2019 00:06:32 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf1-f49.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25112. spamassassin: 3.4.2. Clear:RC:0(209.85.167.49):SA:0(-2.0/5.0):. Processed in 1.977151 secs); 23 Jan 2019 00:06:32 -0000 X-Envelope-From: mikachu@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=ctyECqD0yRgKdG6nWCfOL07QKzuGf3g3xwuEsf0MaD4=; b=E5rXPdVc+69hQQTGaBFOzMssONC99oTXZwWS3oHsd+QwL5gsacuG4aPXvKz4wFv2P9 DrzZqbtnpwIq2iIHm1dKuFiAFk0ZAGLU+ISpTowpi/96m25f30r6fFtpA23S6gZ+WqtB FTsXdTymO7XVA5vuVSRvNNu6LY/g6lNqofEoAICHSq7QNvnxtphsVlXxX42b3fZA1r8E 1tq67ULlZjhjVPffwhw/AgwzKrW8EoP93jWZ8GuMkDpg6krx0wGn6FF0o6kbS7z2fZ2f JaCxCG73jzVZOghxCfxAAbnXsuRxQUpAW0g+h91hQ2Jh6jVYOgljalZQEnsXrL16mhux iqzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=ctyECqD0yRgKdG6nWCfOL07QKzuGf3g3xwuEsf0MaD4=; b=G5Bb5hzE565WAd/c/vwoUs0yX7vgTiuhY9D8cffQnHeh4qTgjZhlZ3grYnkU33a3wF ed9+Q+/TaN0TWjYmfdgt1Pa7x1bTcdW9hUcS78/rjukhkRs8dsPRw4zvWmpPJX20c6Vx az/CrNO1f/VsYolIjbEQVFf6pMX7kEAHP+YUuQEVgyS42vavnn3/3trD8rPDhh+j7t/T fInHACeI/LdBDWxXDl6crBi++nL2YeZJ0LXihUpEicmkBDk+TZsyLer8P9twZ4BKFH1r udJjJvpNcF5rMPlJfqQ8Qa18E9/sdOFPmt7wfOv0xbd5qCaXukeeN1TD9P4CRItNtUg0 aa7A== X-Gm-Message-State: AJcUukcgU8WiBs3F0NcZiIw4bupH7C1ktPrKQN2qnzur9F+J3YKJLU93 3he2lfiAhoq4nxEm1WfT2eYasrxC X-Google-Smtp-Source: ALg8bN4M5J9nMVAUZz4OXINmyStc+3xtbVNnWKPoRhicKyhUw0QxazvcWH0oo5FZpnpNhbRFD8bf+Q== X-Received: by 2002:a19:750a:: with SMTP id y10mr613lfe.157.1548201984546; Tue, 22 Jan 2019 16:06:24 -0800 (PST) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Only use fg_start_code for non-truecolor Date: Wed, 23 Jan 2019 01:06:15 +0100 Message-Id: <20190123000615.22241-1-mikachu@gmail.com> X-Mailer: git-send-email 2.15.1 The sequence for truecolor uses a different prefix from palette colors --- Doc/Zsh/zle.yo | 6 ++++-- Src/prompt.c | 33 +++++++++++++++++++++++---------- Test/X04zlehighlight.ztst | 8 ++++---- 3 files changed, 31 insertions(+), 16 deletions(-) This fixes my prompt. We could possibly add a [fb]g_24bit_start_code or something if anyone feels it's necessary. diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index fe4e5bd04e..c2b9f54300 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2671,7 +2671,9 @@ cindex(escape sequences, terminal, for highlighting) cindex(terminal escape sequences for highlighting) item(tt(fg_start_code) (tt(\e[3)))( The start of the escape sequence for the foreground colour. -This is followed by an ASCII digit representing the colour. +This is followed by one to three ASCII digits representing the colour. +Only used for palette colors, i.e. not 24-bit colors specified via a +color triplet. ) item(tt(fg_default_code) (tt(9)))( The number to use instead of the colour to reset the default foreground @@ -2682,7 +2684,7 @@ The end of the escape sequence for the foreground colour. ) item(tt(bg_start_code) (tt(\e[4)))( The start of the escape sequence for the background colour. -This is followed by an ASCII digit representing the colour. +See tt(fg_start_code) above. ) item(tt(bg_default_code) (tt(9)))( The number to use instead of the colour to reset the default diff --git a/Src/prompt.c b/Src/prompt.c index 135aca942a..4603ffba6e 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -2018,11 +2018,13 @@ set_colour_attribute(zattr atr, int fg_bg, int flags) /* Test if current zle_highlight settings are customized, or * the typical "standard" codes */ - if (0 != strcmp(fg_bg_sequences[fg_bg].start, fg_bg == COL_SEQ_FG ? "\e[3" : "\e[4") || - 0 != strcmp(fg_bg_sequences[fg_bg].def, "9") || /* the same in-fix for both FG and BG */ - 0 != strcmp(fg_bg_sequences[fg_bg].end, "m") /* the same suffix for both FG and BG */ - ) { - is_default_zle_highlight = 0; + if (0 != strcmp(fg_bg_sequences[fg_bg].start, fg_bg == COL_SEQ_FG ? TC_COL_FG_START : TC_COL_BG_START) || + /* the same in-fix for both FG and BG */ + 0 != strcmp(fg_bg_sequences[fg_bg].def, TC_COL_FG_DEFAULT) || + /* the same suffix for both FG and BG */ + 0 != strcmp(fg_bg_sequences[fg_bg].end, TC_COL_FG_END)) + { + is_default_zle_highlight = 0; } /* @@ -2035,7 +2037,9 @@ 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 && (is_default_zle_highlight && (colour > 7 || use_termcap))) { + if (!def && !use_truecolor && + (is_default_zle_highlight && (colour > 7 || 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. @@ -2077,21 +2081,30 @@ set_colour_attribute(zattr atr, int fg_bg, int flags) * or the typical true-color code: .start + 8;2;%d;%d;%d + .end * or the typical 256-color code: .start + 8;5;%d + .end */ - strcpy(colseq_buf, fg_bg_sequences[fg_bg].start); + if (use_truecolor) + strcpy(colseq_buf, fg_bg == COL_SEQ_FG ? TC_COL_FG_START : TC_COL_BG_START); + else + strcpy(colseq_buf, fg_bg_sequences[fg_bg].start); ptr = colseq_buf + strlen(colseq_buf); if (def) { - strcpy(ptr, fg_bg_sequences[fg_bg].def); + if (use_truecolor) + strcpy(ptr, fg_bg == COL_SEQ_FG ? TC_COL_FG_DEFAULT : TC_COL_BG_DEFAULT); + else + strcpy(ptr, fg_bg_sequences[fg_bg].def); while (*ptr) ptr++; } 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); + ptr += sprintf(ptr, "%d", colour); } else *ptr++ = colour + '0'; - strcpy(ptr, fg_bg_sequences[fg_bg].end); + if (use_truecolor) + strcpy(ptr, fg_bg == COL_SEQ_FG ? TC_COL_FG_END : TC_COL_BG_END); + else + strcpy(ptr, fg_bg_sequences[fg_bg].end); if (is_prompt) { if (!bv->dontcount) { diff --git a/Test/X04zlehighlight.ztst b/Test/X04zlehighlight.ztst index e14517490e..f162594c9c 100644 --- a/Test/X04zlehighlight.ztst +++ b/Test/X04zlehighlight.ztst @@ -96,7 +96,7 @@ zpty_line 1 p # the line of interest, preserving escapes ("p") zpty_stop 0:basic region_highlight with true-color (hex-triplets) ->0m27m24mCDE|38;2;4;8;16|trueCDE|39| +>0m27m24m38;2;4;8;16mtrueCDE|39| zpty_start zpty_input 'zmodload zsh/nearcolor' @@ -108,7 +108,7 @@ zpty_line 1 p # the line of interest, preserving escapes ("p") zpty_stop 0:basic region_highlight with near-color (hex-triplets at input) ->0m27m24mCDE|38;5;232|trueCDE|39| +>0m27m24mCDE|3232|trueCDE|39| zpty_start zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=green" ); rh2; }' @@ -132,7 +132,7 @@ zpty_line 1 p # the line of interest, preserving escapes ("p") zpty_stop 0:overlapping region_highlight with true-color ->0m27m24mCDE|38;2;0;204;0|tCDE|38;2;204;0;0|rCDE|39|CDE|38;2;0;204;0|ueCDE|39| +>0m27m24m38;2;0;204;0mt38;2;204;0;0mrCDE|39|38;2;0;204;0mueCDE|39| zpty_start zpty_input 'zmodload zsh/nearcolor' @@ -145,7 +145,7 @@ zpty_line 1 p # the line of interest, preserving escapes ("p") zpty_stop 0:overlapping region_highlight with near-color (hex-triplets at input) ->0m27m24mCDE|38;5;40|tCDE|38;5;160|rCDE|39|CDE|38;5;40|ueCDE|39| +>0m27m24mCDE|340|tCDE|3160|rCDE|39|CDE|340|ueCDE|39| %clean -- 2.15.1