From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Only use fg_start_code for non-truecolor
Date: Wed, 23 Jan 2019 01:06:15 +0100 [thread overview]
Message-ID: <20190123000615.22241-1-mikachu@gmail.com> (raw)
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
next reply other threads:[~2019-01-23 0:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-23 0:06 Mikael Magnusson [this message]
2019-01-23 5:05 ` dana
2019-01-23 9:34 ` Peter Stephenson
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=20190123000615.22241-1-mikachu@gmail.com \
--to=mikachu@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).