diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Doc/Zsh/zle.yo | 6 | ||||
-rw-r--r-- | Src/prompt.c | 33 | ||||
-rw-r--r-- | Test/X04zlehighlight.ztst | 8 |
4 files changed, 36 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog index c3ae92cdc..8cefc0d86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-01-23 Mikael Magnusson <mikachu@gmail.com> + + * 44011: Doc/Zsh/zle.yo, Src/prompt.c, Test/X04zlehighlight.ztst: + Only use fg_start_code for non-truecolor + 2018-01-21 dana <dana@dana.is> * 44001: Completion/Zsh/Context/_brace_parameter: Complete (q+) diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index fe4e5bd04..c2b9f5430 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 135aca942..4603ffba6 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 e14517490..f162594c9 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 |