zsh-workers
 help / color / mirror / code / Atom feed
* [BUG?] If true-color is used, overlapping colors do not work
@ 2018-11-07 13:19 Sebastian Gniazdowski
  2018-11-07 14:40 ` Sebastian Gniazdowski
  2018-11-08  3:03 ` Oliver Kiddle
  0 siblings, 2 replies; 22+ messages in thread
From: Sebastian Gniazdowski @ 2018-11-07 13:19 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 2180 bytes --]

Hello
The last test from the attached ztst reveals this. Before-last test
overlapping colors with standard fg=green/fg=red symbols. Result is a
word "true" with "r" in red the rest in green. You can see the colors
by doing cat /tmp/output.

With true color, I get:
--- /tmp/zsh.ztst.77121/ztst.out    2018-11-07 14:11:51.000000000 +0100
+++ /tmp/zsh.ztst.77121/ztst.tout    2018-11-07 14:11:51.000000000 +0100
@@ -2,5 +2,5 @@
 rh2() { region_highlight+=( "1 2 fg=#cc0000" ); }
 zle -N rh_widget
 bindkey "\C-a" rh_widget
-0m32mt31mr39m32mue39m
+0mt38;2;204;0;0mr39mue

The minus-line is not yet updated, inherited from basic 8-colors case
(which is working and overlapped colors can be observed in the
minus-line). But look at the plus-line. It doesn't emit any color for
"t", only true-color red for "r", and then nothing for "ue".

With zsh/nearcolor loaded (test code pasted at the end of this email),
colors are correctly overlapped:

--- /tmp/zsh.ztst.76836/ztst.out    2018-11-07 14:09:32.000000000 +0100
+++ /tmp/zsh.ztst.76836/ztst.tout    2018-11-07 14:09:32.000000000 +0100
@@ -3,5 +3,5 @@
 rh2() { region_highlight+=( "1 2 fg=#cc0000" ); }
 zle -N rh_widget
 bindkey "\C-a" rh_widget
-0m32mt31mr39m32mue39m
+0m38;5;40mt38;5;160mr39m38;5;40mue39m

cat /tmp/output confirms this.

zsh/nearcolor test case:

  zpty_start
  zpty_input 'zmodload zsh/nearcolor'
  zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4
fg=#00cc00" ); rh2; }'
  zpty_input 'rh2() { region_highlight+=( "1 2 fg=#cc0000" ); }' # `r'
in red; the above line would be too long
  zpty_input 'zle -N rh_widget'
  zpty_input 'bindkey "\C-a" rh_widget'
  zpty_input $'\C-a'
  zpty_line 5   # 3 lines echoed back + 3 empty lines (zpty bug)
  zpty_line 1 p
  zpty_stop
0:overlapping region_highlight with true-color
>zmodload zsh/nearcolor
>rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#00cc00" ); rh2; }
>rh2() { region_highlight+=( "1 2 fg=#cc0000" ); }
>zle -N rh_widget
>bindkey "\C-a" rh_widget
>0m32mt31mr39m32mue39m
>exit

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

[-- Attachment #2: X04highlight.ztst.txt --]
[-- Type: text/plain, Size: 5018 bytes --]

# Tests for region_highlight, true-color support, near-color support

%prep

  if [[ $OSTYPE == cygwin ]]; then
    ZTST_unimplemented='the zsh/zpty module does not work on Cygwin'
  elif zmodload zsh/zpty 2> /dev/null; then
    zpty_start() {
      export PS1= PS2=
      zpty -d
      zpty zsh "${(q)ZTST_testdir}/../Src/zsh -fiV"
    }
    zpty_input() {
      zpty -w zsh "$1" ${${(M)2:#nl}:+$'\n'}
    }
    zpty_line() {
      setopt localoptions extendedglob noshwordsplit
      local REPLY cm=$'\r'
      integer i
      for (( i = 0; i < ${1:-1}; ++i )); do
        zpty -r zsh REPLY
        # P is for "preserve", induces keeping some
        # color codes to test region_highlight, etc.
        # The color codes are then made regular text
        [[ "$2" = "p" ]] && {
            print -rl -- "$REPLY" >> /tmp/output # THE LINE
            REPLY=${REPLY//$'\x1b'\[([2][0-9;]m|[JK]|\?[0-9]##(h|l))/}
            REPLY=${REPLY//(#b)$'\x1b'\[([0-9;]##m)/${match[1]}}
        } || {
            REPLY=${REPLY//$'\x1b'\[([0-9;]##m|[JK]|\?[0-9]##(h|l))/}
        }
        # Fix e^Mexit - match ((?)\r(?)), if \2 == \3, then replace with \2
        # otherwise replace with \1 stripped out of leading/trailing [[:space:]]
        REPLY=${REPLY//(#b)((?(#c0,1))$cm(?(#c0,1)))/${${${(M)match[2]:#${match[3]}}:+${match[2]}}:-${${match[1]##[[:space:]]##}%%[[:space:]]##}}}
        [[ -n "$REPLY" ]] && print -r -- ${${REPLY%%[[:space:]]##}##[[:space:]]##}
      done
    }
    zpty_stop() {
      setopt localoptions extendedglob
      local REPLY cm=$'\r'
      zpty -w zsh $'exit\n'
      # zpty gives no output when piped without these braces (?)
      # The while loop with // substitution is to convert `e^Mexit'
      # into `exit' (see zpty_line). The sed commands remove escapes
      { zpty -r zsh } | sed $'/[^[:space:]]/!d; s/\r$//; s/\x1b\\[[0-9;]*m//g; s/\x1b\\[[JK]//g; s/\x1b\\[?[0-9]*[hl]//g' | while read REPLY; do REPLY=${REPLY//(#b)((?(#c0,1))$cm(?(#c0,1)))/${${${(M)match[2]:#${match[3]}}:+${match[2]}}:-${${match[1]##[[:space:]]##}%%[[:space:]]##}}}; print -r -- "$REPLY"; done
      zpty -d
      :
    }
  else
    ZTST_unimplemented='the zsh/zpty module is not available'
  fi

%test

  zpty_start
  zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=green" ); }'
  zpty_input 'zle -N rh_widget'
  zpty_input 'bindkey "\C-a" rh_widget'
  zpty_input $'\C-a'
  zpty_line 3
  zpty_line 1 p
  zpty_stop
0:basic region_highlight with 8 colors
>rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=green" ); }
>zle -N rh_widget
>bindkey "\C-a" rh_widget
>0m32mtrue39m
>exit

  zpty_start
  zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#040810" ); }' nl
  zpty_input 'zle -N rh_widget' nl
  zpty_input 'bindkey "\C-a" rh_widget' nl
  zpty_input $'\C-a'
  zpty_line 6   # 3 lines echoed back + 3 empty lines (TODO: wrong -n use)
  zpty_line 1 p
  zpty_stop
0:basic region_highlight with true-color (hex-triplets)
>rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#040810" ); }
>zle -N rh_widget
>bindkey "\C-a" rh_widget
>0m38;2;4;8;16mtrue39m
>exit

  zpty_start
  zpty_input 'zmodload zsh/nearcolor' nl
  zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#040810" ); }' nl
  zpty_input 'zle -N rh_widget' nl
  zpty_input 'bindkey "\C-a" rh_widget' nl
  zpty_input $'\C-a'
  zpty_line 8   # 5 lines echoed back + 5 empty lines (TODO: wrong -n use)
  zpty_line 1 p
  zpty_input 'zmodload -u zsh/nearcolor' nl
  zpty_line 2
  zpty_stop
0:basic region_highlight with near-color (hex-triplets at input)
>zmodload zsh/nearcolor
>rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#040810" ); }
>zle -N rh_widget
>bindkey "\C-a" rh_widget
>0m38;5;232mtrue39m
>zmodload -u zsh/nearcolor
>exit

  zpty_start
  zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=green" ); rh2; }'
  zpty_input 'rh2() { region_highlight+=( "1 2 fg=red" ); }' # `r' in red; the above line would be too long
  zpty_input 'zle -N rh_widget'
  zpty_input 'bindkey "\C-a" rh_widget'
  zpty_input $'\C-a'
  zpty_line 4
  zpty_line 1 p
  zpty_stop
0:overlapping region_highlight with 8 colors
>rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=green" ); rh2; }
>rh2() { region_highlight+=( "1 2 fg=red" ); }
>zle -N rh_widget
>bindkey "\C-a" rh_widget
>0m32mt31mr39m32mue39m
>exit

  zpty_start
  zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#00cc00" ); rh2; }'
  zpty_input 'rh2() { region_highlight+=( "1 2 fg=#cc0000" ); }' # `r' in red; the above line would be too long
  zpty_input 'zle -N rh_widget'
  zpty_input 'bindkey "\C-a" rh_widget'
  zpty_input $'\C-a'
  zpty_line 4
  zpty_line 1 p
  zpty_stop
0:overlapping region_highlight with true-color
>rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#00cc00" ); rh2; }
>rh2() { region_highlight+=( "1 2 fg=#cc0000" ); }
>zle -N rh_widget
>bindkey "\C-a" rh_widget
>0m32mt31mr39m32mue39m
>exit

%clean

  zmodload -ui zsh/zpty

# vim:ft=zsh

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

end of thread, other threads:[~2018-12-11  8:06 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-07 13:19 [BUG?] If true-color is used, overlapping colors do not work Sebastian Gniazdowski
2018-11-07 14:40 ` Sebastian Gniazdowski
2018-11-07 19:19   ` Sebastian Gniazdowski
2018-11-08  3:48     ` Oliver Kiddle
2018-11-08  9:25       ` Sebastian Gniazdowski
2018-11-08  3:03 ` Oliver Kiddle
2018-11-08  9:19   ` Sebastian Gniazdowski
2018-11-09  1:28     ` Oliver Kiddle
2018-11-09 15:39       ` Sebastian Gniazdowski
2018-11-11  0:43       ` Sebastian Gniazdowski
2018-11-11  5:11         ` Sebastian Gniazdowski
2018-11-24 17:32         ` highlight test cases (was Re: [BUG?] If true-color is used, overlapping colors do not work) Oliver Kiddle
2018-11-30  0:34           ` Sebastian Gniazdowski
2018-12-07  1:55             ` [BUG] General 256 colors bug – zle_highlight / fg_start_code, etc. is not respected (was: highlight test cases) Sebastian Gniazdowski
2018-12-07 20:26               ` Sebastian Gniazdowski
2018-12-09 19:13                 ` Daniel Shahaf
2018-12-11  8:06                   ` Sebastian Gniazdowski
2018-12-10  2:54             ` highlight test cases (was Re: [BUG?] If true-color is used, overlapping colors do not work) Oliver Kiddle
2018-12-10 23:51               ` Sebastian Gniazdowski
2018-12-10 23:54                 ` Sebastian Gniazdowski
2018-11-11  5:38       ` X04 zle highlight tests, near-color bug Sebastian Gniazdowski
2018-11-18 15:34         ` Sebastian Gniazdowski

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