1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
| | comptestinit () {
setopt extendedglob
[[ -d $ZTST_testdir/Modules/zsh ]] && module_path=( $ZTST_testdir/Modules )
fpath=( $ZTST_srcdir/../Functions/*~*/CVS(/)
$ZTST_srcdir/../Completion
$ZTST_srcdir/../Completion/*/*~*/CVS(/) )
zmodload -i zsh/zpty || return $?
comptest_zsh=${ZSH:-zsh}
comptest_keymap=e
while getopts vz: opt; do
case $opt in
z) comptest_zsh="$OPTARG";;
v) comptest_keymap="v";;
esac
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
export PS1="<PROMPT>" PS2="" RPS1="" RPS2=""
zpty zsh "$comptest_zsh -f +Z"
zpty -r zsh log1 "*<PROMPT>*" || {
print "first prompt hasn't appeared."
return 1
}
comptesteval \
"export LC_ALL=C" \
"emulate -R zsh" \
"export ZDOTDIR=$ZTST_testdir" \
"module_path=( $module_path )" \
"fpath=( $fpath )" \
"zle_highlight=(bg_start_code:'\<BG ' bg_end_code:'\>' fg_start_code:'\<FG ' fg_end_code:'\>' isearch:bg=1,fg=2)" \
"bindkey -$comptest_keymap" \
'LISTMAX=10000000
stty 38400 columns 80 rows 24
TERM=vt100
setopt zle
autoload -U compinit
compinit -u
zstyle ":completion:*:default" list-colors "no=<NO>" "fi=<FI>" "di=<DI>" "ln=<LN>" "pi=<PI>" "so=<SO>" "bd=<BD>" "cd=<CD>" "ex=<EX>" "mi=<MI>" "tc=<TC>" "sp=<SP>" "lc=<LC>" "ec=<EC>\n" "rc=<RC>"
zstyle ":completion:*" group-name ""
zstyle ":completion:*:messages" format "<MESSAGE>%d</MESSAGE>
"
zstyle ":completion:*:descriptions" format "<DESCRIPTION>%d</DESCRIPTION>
"
zstyle ":completion:*:options" verbose yes
zstyle ":completion:*:values" verbose yes
setopt noalwayslastprompt listrowsfirst completeinword
zmodload zsh/complist
expand-or-complete-with-report () {
print -lr "<WIDGET><expand-or-complete>"
zle expand-or-complete
print -lr - "<LBUFFER>$LBUFFER</LBUFFER>" "<RBUFFER>$RBUFFER</RBUFFER>"
zle clear-screen
zle -R
}
list-choices-with-report () {
print -lr "<WIDGET><list-choices>"
zle list-choices
zle clear-screen
zle -R
}
tcfunc() {
if [[ -n $2 ]]; then
REPLY="<tc=$1,arg=$2>"
else
REPLY="<tc=$1>"
fi
}
zle -T tc tcfunc
comp-finish () {
print "<WIDGET><finish>"
zle kill-whole-line
zle clear-screen
zle -R
}
zle-finish () {
print -lr "<WIDGET><finish>" "BUFFER: $BUFFER" "CURSOR: $CURSOR"
(( region_active )) && print -lr "MARK: $MARK"
zle -K main
zle clear-screen
zle -R
zle send-break
}
term-finish () {
zle kill-buffer
zle clear-screen
print "<finish>"
zle -R
}
zle -N expand-or-complete-with-report
zle -N list-choices-with-report
zle -N comp-finish
zle -N term-finish
zle -N zle-finish
bindkey "^I" expand-or-complete-with-report
bindkey "^D" list-choices-with-report
bindkey "^T" history-incremental-search-forward
bindkey "^XR" history-incremental-pattern-search-backward
bindkey "^XT" history-incremental-pattern-search-forward
bindkey -r "^M"
bindkey "^Mc" comp-finish
bindkey "^Mt" term-finish
bindkey "^Mz" zle-finish
bindkey -a "^Mz" zle-finish
'
}
comptesteval () {
local tmp=/tmp/comptest.$$
print -lr - "$@" > $tmp
zpty -w zsh ". $tmp"
zpty -r -m zsh log_eval "*<PROMPT>*" || {
print "prompt hasn't appeared."
return 1
}
rm $tmp
}
comptest () {
input="$*"
zpty -n -w zsh "$input"$'\C-Mc'
zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
print "failed to invoke finish widget."
return 1
}
logs=(${(s:<WIDGET>:)log})
shift logs
for log in "$logs[@]"; do
if [[ "$log" = (#b)*$'<LBUFFER>'(*)$'</LBUFFER>\r\n<RBUFFER>'(*)$'</RBUFFER>'* ]]; then
print -lr "line: {$match[1]}{$match[2]}"
fi
while (( ${(N)log#*(#b)(<LC><(??)><RC>(*)<EC>|<DESCRIPTION>(*)</DESCRIPTION>|<MESSAGE>(*)</MESSAGE>|<COMPADD>(*)</COMPADD>|<INSERT_POSITIONS>(*)</INSERT_POSITIONS>)} )); do
log="${log[$mend[1]+1,-1]}"
if (( 0 <= $mbegin[2] )); then
if [[ $match[2] != TC && $match[3] != \ # ]]; then
print -lr "$match[2]:{${match[3]%${(%):-%E}}}"
fi
elif (( 0 <= $mbegin[4] )); then
print -lr "DESCRIPTION:{$match[4]}"
elif (( 0 <= $mbegin[5] )); then
print -lr "MESSAGE:{$match[5]}"
elif (( 0 <= $mbegin[6] )); then
print -lr "COMPADD:{${${match[6]}//[$'\r\n']/}}"
elif (( 0 <= $mbegin[7] )); then
print -lr "INSERT_POSITIONS:{${${match[7]}//[$'\r\n']/}}"
fi
done
done
}
zletest () {
input="$*"
zpty -n -w zsh "$input"$'\C-Mz'
zpty -r -m zsh log "*<WIDGET><finish>*<PROMPT>*" || {
print "failed to invoke finish widget."
return 1
}
print -lr "${(@)${(ps:\r\n:)log##*<WIDGET><finish>}[1,-2]}"
}
termtest () {
input="$*"
zpty -n -w zsh "$input"
# clear screen, to clear out control sequences
zpty -n -w zsh $'\C-L'
# send trailing output to scrape off.
zpty -n -w zsh $'\C-Mt\C-U'
zpty -r -m zsh log "*<finish>*<PROMPT>" || {
print "failed to invoke finish widget."
return 1
}
# there might be multiple <PROMPT>'s in log, grab the last one
# generated after the clear screen.
print -lr -- ${${(f)${log%%<finish>*}##*<PROMPT>}%%<tc=c?>*}
}
|