Zsh Mailing List Archive
Messages sorted by:
Re: typeahead problem
- X-seq: zsh-workers 4725
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: "Andrej Borsenkow" <borsenkow.msk@xxxxxx>, "zsh Workers" <zsh-workers@xxxxxxxxxxxxxxx>, Bernd Eggink <eggink@xxxxxxxxxxxxxx>
- Subject: Re: typeahead problem
- Date: Tue, 8 Dec 1998 13:22:28 -0800
- In-reply-to: <001a01be22d9$e99fbc80$21c9ca95@xxxxxxxxxxxxxxx>
- In-reply-to: <366D723D.A710FD4E@xxxxxxxxxxxxxx>
- References: <001a01be22d9$e99fbc80$21c9ca95@xxxxxxxxxxxxxxx> <366D1DC2.2A726728@xxxxxxxxxxxxxxxxxx> <000701be22aa$df12ab80$21c9ca95@xxxxxxxxxxxxxxx> <366D32BB.79BDDC23@xxxxxxxxxxxxxxxxxx> <000a01be22b7$512aedc0$21c9ca95@xxxxxxxxxxxxxxx> <366D40E8.EAB05EE2@xxxxxxxxxxxxxxxxxx> <001101be22c3$12fde9b0$21c9ca95@xxxxxxxxxxxxxxx> <981208100629.ZM6018@xxxxxxxxxxxxxxxxxxxxxxx> <366D723D.A710FD4E@xxxxxxxxxxxxxx>
On Dec 8, 9:38pm, Andrej Borsenkow wrote:
> Subject: RE: typeahead problem
> > I think the choice to pass purge==0 was partly to get consistent script
> > behavior regardless of the availablilty of FIONREAD.
> Unfortunately, it's not consistent. Consistent would be to read the first
> character of typeahead.
> About why it works and does not work.
> getquery() changes tty modes, and on some systems that flushes unread input
> ("clobber typeahead") Looks, like my system is so fast, that even if I type
> several characters, the first one is read by _first_ read -q, then the
> second is read by the _second_ read -q and the others are simply lost.
Your machine executes "sleep 10" so quickly that you can't type before it
> In other words, if system does have FIONREAD but clobbers typeahead, zsh
> always reads the first character and forgets the rest.
That shouldn't be how it works. If the system clobbers typeahead in the
way described in Src/Zle/zle_main.c, then the typeahead should get lost
before getquery() has a chance to read even the first character.
However, it is the case that zsetterm() and getquery() are inconsistent
about their use of FIONREAD. zsetterm() calls ioctl(FIONREAD) _before_
attaching to the TTY, whereas getquery() attaches first and then calls
ioctl(). If the zsetterm() code doesn't cause a problem with spurious
SIGTTIN and SIGTTOU signals, it should be safe to move the FIONREAD code
in getquery() to above the attachtty() and setcbreak().
> CLOBBER_TYPEAHED is used in zsetterm() but not in getquery() ...
Yes, but that doesn't make any difference [except for the inconsistency
I just noted], because getquery() already performs an equivalent test on
the value obtained from ioctl(FIONREAD).
> ... Well, do we need to change modes (setcbreak()) _before_ doing read?
Yes, but apparently not before doing ioctl(FIONREAD).
On Dec 8, 7:38pm, Bernd Eggink wrote:
> Subject: Re: typeahead problem
> Bart Schaefer wrote:
> > The question is which of those two cases `read -q` should emulate. The
> > decision made was to treat it like spell checking, leaving the typeahead
> > alone when possible so that other commands may consume it.
> IMHO this decision was wrong, but it's probabely too late now.
Actually, I don't get the impression that `read -q` is all that widely
used, and as it's already inconsistent depending on FIONREAD, this might
be a reasonable change. We should probably float it on zsh-users first,
> > get the "always consume one character" behavior is to use
> > read -k1 "REPLY?Yes or no: " && do_something
> Hm, no. You have to write something like
> typeset -u REPLY
> read -k1 "REPLY?Yes or no: "
> [[ $REPLY == Y ]] && do_something
Well, yes, but you should still test for success of read. I assumed you
were already testing $REPLY inside "do_something" ... if you don't need
the answer captured in $REPLY, you can just do
read -q "?Yes or no: " && ...
Messages sorted by: