Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: one time in 20 error



On Tue, Dec 6, 2022 at 12:48 AM Oliver Kiddle <opk@xxxxxxx> wrote:
>
> On 29 Nov, Roman Perepelitsa wrote:
> > 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.
>
> This is a nice idea. I've occasionally had unwanted effects from
> unintentionally hitting a function key.

That's its intended purpose. I learned about readline's
skip-csi-sequence here: https://www.reddit.com/r/zsh/comments/yzhx3l.
Docs: https://www.gnu.org/software/bash/manual/html_node/Miscellaneous-Commands.html#index-skip_002dcsi_002dsequence-_0028_0029

"""
skip-csi-sequence ()

Read enough characters to consume a multi-key sequence such as those
defined for keys like Home and End. Such sequences begin with a
Control Sequence Indicator (CSI), usually ESC-[. If this sequence is
bound to "\e[", keys producing such sequences will have no effect
unless explicitly bound to a Readline command, instead of inserting
stray characters into the editing buffer. This is unbound by default,
but usually bound to ESC-[.
"""

> The patch below tries the widget approach. Rather than look for the
> termination character, I thought it better to bail out given any
> out-of-range parameter byte [...]

Good idea. This is also how readline does it.

> [...] or KEYTIMEOUT being exceeded

Probably also a good idea, although readline doesn't have a timeout.

Is there an advantage to implementing this widget in C rather than zsh?

Roman.




Messages sorted by: Reverse Date, Date, Thread, Author