From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Risto Laitinen <risto.laitinen@gmail.com>
Cc: Ray Andrews <rayandrews@eastlink.ca>, Zsh Users <zsh-users@zsh.org>
Subject: Re: one time in 20 error
Date: Tue, 29 Nov 2022 11:13:24 +0100 [thread overview]
Message-ID: <CAN=4vMpCUNgKYgSR+4rmREpA25v_sLHYcS4nfTk8EQ_0Cg5yyw@mail.gmail.com> (raw)
In-Reply-To: <CAA-Ti-hhbwZD3-aeMvy_tm5f7SKHw7XN4muJn8ymez1q7rAE_A@mail.gmail.com>
On Tue, Nov 29, 2022 at 3:49 AM Risto Laitinen <risto.laitinen@gmail.com> wrote:
>
> It is a mouse event (SGR report mode)
Thanks!
So here's what's probably happening. The script is enabling mouse
tracking, the user clicks with the mouse, the script disables mouse
tracking and exits before reading the mouse event, zle reads the mouse
event.
The script needs to read from the TTY after disabling mouse tracking.
Reading with timeout is suboptimal because there is no upper bound on
input latency (imagine working over SSH). A better solution is to send
a query and read the response. Something like this perhaps:
function cleanup() {
emulate -L zsh -o extended_glob
# Disable mouse tracking.
print -n '\e[?1000l'
# Disable SGR mouse mode.
print -n '\e[?1006l'
# Query the TTY (Primary Device Identification).
print -n '\e[0c'
# Read stdin until we find the response to our query.
local resp
while [[ $resp != *$'\e[?'(<->\;)#<->c ]] &&
read -skr 'resp[$#resp+1]'; do
# Do nothing.
done
}
This function needs to be invoked before the script exits.
There is probably a better solution to this problem.
Roman.
P.S.
I have the following in my .zshrc:
function skip-csi-sequence() {
local key
while read -sk key && (( $((#key)) < 0x40 || $((#key)) > 0x7E )); do
# empty body
done
}
zle -N skip-csi-sequence
bindkey '\e[' skip-csi-sequence
With this binding a buggy script that leaks mouse events into zle
won't have any effect.
next prev parent reply other threads:[~2022-11-29 10:14 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 17:40 Ray Andrews
2022-11-28 17:54 ` Roman Perepelitsa
2022-11-28 20:34 ` Ray Andrews
2022-11-28 20:46 ` Roman Perepelitsa
2022-11-28 22:16 ` Ray Andrews
2022-11-28 22:24 ` Roman Perepelitsa
2022-11-28 23:18 ` Ray Andrews
2022-11-29 2:48 ` Risto Laitinen
2022-11-29 3:27 ` Ray Andrews
2022-11-29 10:13 ` Roman Perepelitsa [this message]
2022-11-29 13:29 ` Ray Andrews
2022-11-30 4:32 ` Bart Schaefer
2022-11-30 13:56 ` Ray Andrews
2022-11-30 14:10 ` Roman Perepelitsa
2022-11-30 20:23 ` Ray Andrews
2022-11-30 23:17 ` Ray Andrews
2022-11-30 23:46 ` Bart Schaefer
2022-12-01 0:03 ` Bart Schaefer
2022-12-01 3:20 ` Ray Andrews
2022-12-01 9:19 ` Roman Perepelitsa
2022-12-01 14:35 ` Ray Andrews
2022-12-01 14:42 ` Philippe Altherr
2022-12-01 21:19 ` Ray Andrews
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='CAN=4vMpCUNgKYgSR+4rmREpA25v_sLHYcS4nfTk8EQ_0Cg5yyw@mail.gmail.com' \
--to=roman.perepelitsa@gmail.com \
--cc=rayandrews@eastlink.ca \
--cc=risto.laitinen@gmail.com \
--cc=zsh-users@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).