Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Cannot invoke widget within zpty, with \C-a nor a
- X-seq: zsh-workers 43775
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: Cannot invoke widget within zpty, with \C-a nor a
- Date: Tue, 6 Nov 2018 20:53:58 +0100
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CSyWp8LEWzrsNpHUDNYpG96QAAulPn1FYlWEXfHjqNc=; b=cCCyHcx47VIrLxZS6hvBOmmJysxb9Nd0CC7pyITw7XB04CbEsHDy9gahD4IueK3tF0 XnSMqhY9sKtTFN7xt2dBD+1fAkoXn9FoRSt+5FD7+XOkaQiGcwLpw07uDfwCkBAMm96q +SsBFYRUwWxK3fsWRfoY9VCtnwUvb6JxKd1biA0BKySBoER+R+bOUMD1jWBVacAHb98p yS1kpVL4tv6fcBs6VRAUcBCDq9KcqH6k0NK8RUIN9CGZfb6RgTOeVYfhm8CkHPJiNKsS 1flPMDA5CP3CFR8I8m3MQgiLvk3uEZQ/6saRH+tJ7HFR9a4eN1axOUrZxImh7I4YJYFQ JC5Q==
- In-reply-to: <1541524520.4076.6.camel@samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVA5BKywt0GEgJUWcC57bFqC6emwGthZQPe2YmcnA9HFYg@mail.gmail.com> <CGME20181106170945epcas4p1d6fa583ec3fd331f2ffdbc8d9cbc2109@epcas4p1.samsung.com> <CAKc7PVD=j1EmLWDen+YoAKZMBiOr5AcEGJ8h=yRrpbsS5Mc=Wg@mail.gmail.com> <1541524520.4076.6.camel@samsung.com>
On Tue, 6 Nov 2018 at 18:16, Peter Stephenson <p.stephenson@xxxxxxxxxxx> 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
# 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author