From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Cannot invoke widget within zpty, with \C-a nor a
Date: Tue, 6 Nov 2018 20:53:58 +0100 [thread overview]
Message-ID: <CAKc7PVBHfUUZV1fhCW0VHpTifjOcM-oj3ryme2ELpVC26tunPQ@mail.gmail.com> (raw)
In-Reply-To: <1541524520.4076.6.camel@samsung.com>
[-- 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
next prev parent reply other threads:[~2018-11-06 19:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 15:19 Sebastian Gniazdowski
2018-11-06 17:08 ` Sebastian Gniazdowski
2018-11-06 17:15 ` Peter Stephenson
2018-11-06 19:53 ` Sebastian Gniazdowski [this message]
2018-11-06 19:55 ` Sebastian Gniazdowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKc7PVBHfUUZV1fhCW0VHpTifjOcM-oj3ryme2ELpVC26tunPQ@mail.gmail.com \
--to=sgniazdowski@gmail.com \
--cc=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).