* Cannot invoke widget within zpty, with \C-a nor a @ 2018-11-06 15:19 Sebastian Gniazdowski 2018-11-06 17:08 ` Sebastian Gniazdowski 0 siblings, 1 reply; 5+ messages in thread From: Sebastian Gniazdowski @ 2018-11-06 15:19 UTC (permalink / raw) To: Zsh hackers list [-- Attachment #1: Type: text/plain, Size: 1279 bytes --] Hello, I've attached complete test file. The test body is: zpty_start zpty_input 'stty 38400 columns 80 rows 24 tabs -icanon -iexten' nl zpty_input 'rh_widget() { BUFFER="ls"; region_highlight+=( 0 4 "fg=#12569a" ); echo yes; }' nl zpty_input 'zle -N rh_widget' nl zpty_input 'bindkey "\C-a" rh_widget' nl zpty_input 'zle -la | grep rh_widget' nl zpty_input 'bindkey | grep rh_widget' nl zpty_input $'\C-a' zpty_stop 0:region_highlight *>*ls* The result is always: Pattern match filead, line mismatch (1/3): <*ls* >rh_widget >"^A" rh_widget >zsh: command not found: ^A Note that the 2 middle lines confirm the widget is created and bound to Ctrl-A. I can change Ctrl-A sequence to just letter "a", and the result is the same. I've tried also without the first stty command (I was looking for some needed initialization in Y0* completion tests, that's why it's there). What can be the cause? Ctrl-T was invoking TTY "status" command, which on BSD gives system load. So I've changed to TTY-unused Ctrl-A. I just need to invoke zle widget so if there is other method (zle -F didn't work) I can use it. -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org [-- Attachment #2: D10highlight.txt --] [-- Type: text/plain, Size: 1372 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 +Z" } zpty_input() { zpty -w zsh "$1" ${${(M)2:#nl}:+$'\n'} } zpty_line() { local REPLY integer i for (( i = 0; i < ${1:-1}; ++i )); do zpty -r zsh REPLY print -r -- ${REPLY%%($'\r\n'|$'\n')} done } zpty_stop() { # exit twice in case of check_jobs zpty -w zsh $'exit\nexit\n' # zpty gives no output when piped without these braces (?) { zpty -r zsh } | sed $'/[^[:space:]]/!d; s/\r$//;' zpty -d : } else ZTST_unimplemented='the zsh/zpty module is not available' fi %test zpty_start zpty_input 'stty 38400 columns 80 rows 24 tabs -icanon -iexten' nl zpty_input 'rh_widget() { BUFFER="ls"; region_highlight+=( 0 4 "fg=#12569a" ); echo yes; }' nl zpty_input 'zle -N rh_widget' nl zpty_input 'bindkey "\C-a" rh_widget' nl zpty_input 'zle -la | grep rh_widget' nl zpty_input 'bindkey | grep rh_widget' nl zpty_input $'\C-a' zpty_stop 0:region_highlight *>*ls* %clean zmodload -ui zsh/zpty # vim:ft=zsh ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Cannot invoke widget within zpty, with \C-a nor a 2018-11-06 15:19 Cannot invoke widget within zpty, with \C-a nor a Sebastian Gniazdowski @ 2018-11-06 17:08 ` Sebastian Gniazdowski 2018-11-06 17:15 ` Peter Stephenson 0 siblings, 1 reply; 5+ messages in thread From: Sebastian Gniazdowski @ 2018-11-06 17:08 UTC (permalink / raw) To: Zsh hackers list On Tue, 6 Nov 2018 at 16:19, Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote: > > Hello, > I've attached complete test file. The test body is: > > zpty_start > zpty_input 'stty 38400 columns 80 rows 24 tabs -icanon -iexten' nl > zpty_input 'rh_widget() { BUFFER="ls"; region_highlight+=( 0 4 > "fg=#12569a" ); echo yes; }' nl > zpty_input 'zle -N rh_widget' nl > zpty_input 'bindkey "\C-a" rh_widget' nl > zpty_input 'zle -la | grep rh_widget' nl > zpty_input 'bindkey | grep rh_widget' nl > zpty_input $'\C-a' > zpty_stop > 0:region_highlight > *>*ls* I now see that testing the running of zle widgets is in general difficult, even with zpty. X03zlebindkey.ztst does only `-s' bindkeys, which do not run a zle-widget, `zle && true || echo nozle' will display "nozle". I would believe that this is lost game, as even this didn't work as expected: rh_widget() { local FD="$1"; zle -F -w $FD; exec {FD}<&-; BUFFER="ls"; region_highlight+=( 0 4 "fg=#12569a" ); echo yes | tee -a /tmp/reply; }; zle -N rh_widget FD=1337; exec {FD}< <( LANG=C sleep 0.5; echo run | tee -a /tmp/reply ); command true; zle -F -w "$FD" rh_widget ... however, it turned out that the `+Z' option passed to zsh-binary (its meaning: disable Zle) was responsible for not interpreting any key sequences (and not activating zle -F, however removing +Z didn't help here actually). I now have the `rh_widget' called after zpty -w zsh $'\C-a'. The `region_highlight' tests (brought up because of wanting to test true/near-color, but also revealed that general `rh' use is untested and this rather should change) seem to be possible to write. -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Cannot invoke widget within zpty, with \C-a nor a 2018-11-06 17:08 ` Sebastian Gniazdowski @ 2018-11-06 17:15 ` Peter Stephenson 2018-11-06 19:53 ` Sebastian Gniazdowski 0 siblings, 1 reply; 5+ messages in thread From: Peter Stephenson @ 2018-11-06 17:15 UTC (permalink / raw) To: zsh-workers On Tue, 2018-11-06 at 18:08 +0100, Sebastian Gniazdowski wrote: > I now see that testing the running of zle widgets is in general > difficult, even with zpty. For sure. zpty just doesn't provide a robust enough platform, at least in its current state. This is true for the job control tests, too, with the asymmetric messages popping up. I've been groping for suggestions but haven't really got any directions. pws ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Cannot invoke widget within zpty, with \C-a nor a 2018-11-06 17:15 ` Peter Stephenson @ 2018-11-06 19:53 ` Sebastian Gniazdowski 2018-11-06 19:55 ` Sebastian Gniazdowski 0 siblings, 1 reply; 5+ messages in thread From: Sebastian Gniazdowski @ 2018-11-06 19:53 UTC (permalink / raw) To: Peter Stephenson; +Cc: Zsh hackers list [-- Attachment #1: Type: text/plain, Size: 1605 bytes --] On Tue, 6 Nov 2018 at 18:16, Peter Stephenson <p.stephenson@samsung.com> wrote: > > On Tue, 2018-11-06 at 18:08 +0100, Sebastian Gniazdowski wrote: > > I now see that testing the running of zle widgets is in general > > difficult, even with zpty. > > For sure. zpty just doesn't provide a robust enough platform, at least > in its current state. This is true for the job control tests, too, with > the asymmetric messages popping up. > > I've been groping for suggestions but haven't really got any directions. I've managed to test region_highlight altered in zle widget, triggered by zpty -w zsh $'\C-a', with zpty-zshell running without +Z (i.e. no disabling of Zle). Use of Zle means that test's commands will be echoed back, but it doesn't look bad, e.g.: 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 zpty_line 1 p # o is for "preserve" – to keep colour escapes converting them to regular strings 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 Complete ztst-file is attached. Is there a chance it will be added to upstream? -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org [-- Attachment #2: D10highlight.txt --] [-- Type: text/plain, Size: 3138 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" ]] && { 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" ); }' 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 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 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 %clean zmodload -ui zsh/zpty # vim:ft=zsh ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Cannot invoke widget within zpty, with \C-a nor a 2018-11-06 19:53 ` Sebastian Gniazdowski @ 2018-11-06 19:55 ` Sebastian Gniazdowski 0 siblings, 0 replies; 5+ messages in thread From: Sebastian Gniazdowski @ 2018-11-06 19:55 UTC (permalink / raw) To: Peter Stephenson; +Cc: Zsh hackers list On Tue, 6 Nov 2018 at 20:53, Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote: > Complete ztst-file is attached. Is there a chance it will be added to upstream? I mean: after I work on a few tests, including near-color side to true-color and some region_highlight tricks (like overlapping ranges). -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-11-06 19:56 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-11-06 15:19 Cannot invoke widget within zpty, with \C-a nor a Sebastian Gniazdowski 2018-11-06 17:08 ` Sebastian Gniazdowski 2018-11-06 17:15 ` Peter Stephenson 2018-11-06 19:53 ` Sebastian Gniazdowski 2018-11-06 19:55 ` 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).