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

Re: one time in 20 error

On Wed, Nov 30, 2022 at 5:56 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> Well, so far the 'timeout' is working 100%, still I myself would sorta
> build that in to 'zcurses end'.  While in zcurses,it owns all inputs so
> on quitting the idea that some input would be 'forwarded' to the
> terminal seems strange.

Suppose you have a curses program that's controlled from the keyboard,
and when you type shift-Q that program calls "zcurses end".  Now, you
happen to be a 300-words-per-minute typist, so upon hitting Q you
instinctively begin typing the first word of the next command that you
expect to execute, without waiting for a prompt.  Should zcurses
swallow up all or part of that command because it "owns" the input?

> As you say there are these
> 'generated by the terminal' ... but I don't know anything about such
> things.  Seems to me the terminal receives input, not makes input

Everything about ANSI terminal control is unfortunately "in-band":
There is only one data stream between whatever program is using the
terminal (zsh in this case) and the terminal itself, which
(importantly) includes the keyboard.  All those weird sequences
starting with ^[[ or similar are still sent to (and from!) the
terminal via the same stream as the prompt or the output of "ls" or
your typing or copy-pasting or whatever.  In the "to" direction, the
terminal notices ^[[ followed by something, and interprets it as a
command (change the color, move the cursor, etc.) instead of as
"normal" characters to be displayed.  Some of those commands ask the
terminal for data (tell me the cursor position, tell me where the
mouse was clicked, etc.).  In that case data is sent in the "from"
direction:  the terminal writes ^[[ followed by the requested data,
and the program using the terminal is expected to recognize the ^[[ as
"not normal" and read it -- but there's nothing else to distinguish
that from something that was typed on the keyboard, it's all on the
same stream.  So unless the program is waiting for one of those ^[[
sequences, it responds as if you typed it.

One of Roman's hacks (his skip-csi-sequence function) is to make zsh
ALWAYS be "waiting for" one of those sequences, so as to throw it away
if it wasn't really requested.

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