zsh-workers
 help / Atom feed
* [PATCH] Improve the X04zlehighlight test
@ 2019-02-07 21:06 Daniel Tameling
  2019-02-07 21:14 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Tameling @ 2019-02-07 21:06 UTC (permalink / raw)
  To: zsh-workers

Dear all,

I have tried to modify the zle highlight test so that the TERM
variable isn't set explicitly anymore so people can check with the
actual terminal they are using that the features behave as expected.

The following things are changed: in REPLY, the enter and exit
standout mode sequences are replaced with their xterm equivalents
because other terminals (like screen-256color) use different
sequences. The old nearcolor tests are now only executed when the
terminal has exactly 256 colours because only then they produce
meaningful results. In turn, equivalent tests for 88 colour terminals
are added.

I tested the new X04 successfully with TERM set to various xterms and
a few other terminals. The test seems to be surprisingly stable with
regards to the number of colours of the terminal. But overall I am not
overly optimistic that the test will pass with all terminals/operating
systems. The tests feel very brittle. So please try it out.

Best regards, 
Daniel

diff --git a/Test/X04zlehighlight.ztst b/Test/X04zlehighlight.ztst
index 000949698..4afdf6c7c 100644
--- a/Test/X04zlehighlight.ztst
+++ b/Test/X04zlehighlight.ztst
@@ -2,9 +2,8 @@
 # Version 0.7 2018-12-06
 %prep
 
-  export TERM=xterm-256color
-  if [[ ${+termcap} != 1 || ${termcap[Co]} != <-> || ${termcap[Co]} -lt 256 ]]; then
-    ZTST_unimplemented="no termcap module OR termcap doesn't support 256 or more colors"
+  if [[ ${+termcap} != 1 || ${termcap[Co]} != <-> ]]; then
+    ZTST_unimplemented="no termcap module OR termcap doesn't support colors"
   elif [[ $OSTYPE == cygwin ]]; then
     ZTST_unimplemented='the zsh/zpty module does not work on Cygwin'
   elif zmodload zsh/zpty 2> /dev/null; then
@@ -31,6 +30,9 @@
         zpty -r zsh REPLY
         # Normalise me/sgr0 to \e[0m. We also need to strip \e(B in zpty_stop()
         REPLY=${REPLY//${termcap[me]}/$'\x1b[0m'}
+        # Replace rmso/se and smso/so with xterm values
+        REPLY=${REPLY//${termcap[so]}/$'\x1b[7m'}
+        REPLY=${REPLY//${termcap[se]}/$'\x1b[27m'}
         # P is for "preserve", and induces keeping some
         # expected color codes to test region_highlight,
         # etc. - the color codes are made a regular text.
@@ -105,6 +107,9 @@
 0:basic region_highlight with true-color (hex-triplets)
 >0m27m24m38;2;4;8;16mtrueCDE|39|
 
+  if [[ ${termcap[Co]} != 256 ]]; then
+    ZTST_skip="nearcolor module for 256 color terminals"
+  fi
   zpty_start
   zpty_input 'zmodload zsh/nearcolor'
   zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#040810" ); }'
@@ -117,6 +122,21 @@
 0:basic region_highlight with near-color (hex-triplets at input)
 >0m27m24mCDE|3232|trueCDE|39|
 
+  if [[ ${termcap[Co]} != 88 ]]; then
+    ZTST_skip="nearcolor module for 88 color terminals"
+  fi
+  zpty_start
+  zpty_input 'zmodload zsh/nearcolor'
+  zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#040810" ); }'
+  zpty_input 'zle -N rh_widget'
+  zpty_input 'bindkey "\C-a" rh_widget'
+  zpty_enable_zle
+  zpty_input $'\C-a'  # emits newline, which executes BUFFER="true" command
+  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|316|trueCDE|39|
+
   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
@@ -141,6 +161,9 @@
 0:overlapping region_highlight with true-color
 >0m27m24m38;2;0;204;0mt38;2;204;0;0mrCDE|39|38;2;0;204;0mueCDE|39|
 
+  if [[ ${termcap[Co]} != 256 ]]; then
+    ZTST_skip="nearcolor module for 256 color terminals"
+  fi
   zpty_start
   zpty_input 'zmodload zsh/nearcolor'
   zpty_input 'rh_widget() { BUFFER="true"; region_highlight+=( "0 4 fg=#00cc00" ); rh2; }'
@@ -154,6 +177,22 @@
 0:overlapping region_highlight with near-color (hex-triplets at input)
 >0m27m24mCDE|340|tCDE|3160|rCDE|39|CDE|340|ueCDE|39|
 
+  if [[ ${termcap[Co]} != 88 ]]; then
+    ZTST_skip="nearcolor module for 88 color terminals"
+  fi
+  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_enable_zle
+  zpty_input $'\C-a'  # emits newline, which executes BUFFER="true" command
+  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|324|tCDE|348|rCDE|39|CDE|324|ueCDE|39|
+
 %clean
 
   zmodload -ui zsh/zpty

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

* Re: [PATCH] Improve the X04zlehighlight test
  2019-02-07 21:06 [PATCH] Improve the X04zlehighlight test Daniel Tameling
@ 2019-02-07 21:14 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2019-02-07 21:14 UTC (permalink / raw)
  To: zsh-workers

On Thu, Feb 7, 2019 at 1:07 PM Daniel Tameling <tamelingdaniel@gmail.com> wrote:
>
> I have tried to modify the zle highlight test so that the TERM
> variable isn't set explicitly anymore so people can check with the
> actual terminal they are using that the features behave as expected.

This is well-meaning but slightly misguided.  The tests are often run
by automated systems that aren't connected to a terminal or that have
TERM set to a dummy entry with no useful values.

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 21:06 [PATCH] Improve the X04zlehighlight test Daniel Tameling
2019-02-07 21:14 ` Bart Schaefer

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/ public-inbox