zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Only use fg_start_code for non-truecolor
@ 2019-01-23  0:06 Mikael Magnusson
  2019-01-23  5:05 ` dana
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2019-01-23  0:06 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Only use fg_start_code for non-truecolor
  2019-01-23  0:06 PATCH: Only use fg_start_code for non-truecolor Mikael Magnusson
@ 2019-01-23  5:05 ` dana
  2019-01-23  9:34   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: dana @ 2019-01-23  5:05 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-workers

On 22 Jan 2019, at 18:06, Mikael Magnusson <mikachu@gmail.com> wrote:
>This fixes my prompt. We could possibly add a [fb]g_24bit_start_code or
>something if anyone feels it's necessary.

I tested this on macOS and it seems OK. At least, it makes sense to me, and it
appears to work as described.

As for the file-completion thing (workers/44009), if my opinion is wanted: I
think i would have worked around it in 'user land' myself, but i don't feel
strongly either way. If coming to a firm conclusion on it might delay getting
5.7 into Buster, we could revert it pending further discussion? idk.

In any case, do we need one more test release after this fix goes in? Or does
it look safe enough?

dana


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Only use fg_start_code for non-truecolor
  2019-01-23  5:05 ` dana
@ 2019-01-23  9:34   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2019-01-23  9:34 UTC (permalink / raw)
  To: zsh-workers

On Tue, 2019-01-22 at 23:05 -0600, dana wrote:
> In any case, do we need one more test release after this fix goes in? Or does
> it look safe enough?

As long as Mikael and Sebastian think their set-ups are good enough I
think we're OK --- as far as I remember this wasn't the sort of thing
people using test releases picked up on.  (Though once it's out in the
world the floodgates may open.)

Thinks all for getting this sorted.
pws


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-23  9:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-23  0:06 PATCH: Only use fg_start_code for non-truecolor Mikael Magnusson
2019-01-23  5:05 ` dana
2019-01-23  9:34   ` Peter Stephenson

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).