zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Bernd Eggink <eggink@uni-hamburg.de>,
	zsh Workers <zsh-workers@math.gatech.edu>,
	"Andrej Borsenkow" <borsenkow.msk@sni.de>
Subject: Re: typeahead problem
Date: Tue, 8 Dec 1998 10:06:29 -0800	[thread overview]
Message-ID: <981208100629.ZM6018@candle.brasslantern.com> (raw)
In-Reply-To: <366D1DC2.2A726728@rrz.uni-hamburg.de>
In-Reply-To: <000701be22aa$df12ab80$21c9ca95@mowp.siemens.ru>
In-Reply-To: <366D32BB.79BDDC23@rrz.uni-hamburg.de>
In-Reply-To: <000a01be22b7$512aedc0$21c9ca95@mowp.siemens.ru>
In-Reply-To: <366D40E8.EAB05EE2@rrz.uni-hamburg.de>
In-Reply-To: <001101be22c3$12fde9b0$21c9ca95@mowp.siemens.ru>

On Dec 8,  1:38pm, Bernd Eggink wrote:
} Subject: typeahead problem
}
}   read -q "REPLY?Yes or no: " && do_something
} 
} Now if "do_something" takes some time and you type at least one
} character in advance, 'read -q' behaves as if you are constantly typing
} 'n', until you consume the pending character by a normal 'read'. In
} other words, if you do NOT issue a normal read, EVERY following 'read
} -q' will behave as if you had typed 'n', until the end of the script.
} 
} Is there a rationale for this feature  (which I still consider a bug,
} because it makes 'read -q' nearly unusable, at least in scripts)?

Andrej has been telling you mostly the right things ...

On Dec 8,  6:54pm, Andrej Borsenkow wrote:
} As to why it is taken for "no" - imagine, you typed something _before_
} read -q, and that was not completely consumed - you definitely does not want
} some leftover "y" to remove your valuable files :) so it tries to play safe.

The getquery() function is called for the `rm *` check (the one DISabled
by `setopt rmstarsilent`) and for spell checking (`setopt correct`) as
well as for read -q.  In those cases, typeahead is considered undesirable,
and in the spell-check case zsh wants to leave it available in case the
user intended it as input for the command.  In the `rm *` case, on systems
that support ioctl(FIONREAD), zsh consumes all the typeahead before it
prints the query.

On systems that don't support FIONREAD, zsh always consumes one character.

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.  The way you
get the "always consume one character" behavior is to use

	read -k1 "REPLY?Yes or no: " && do_something

so having `read -q` available as an alternative that does NOT consume any
characters is more flexible.  The problem this leaves that there's no way
to emulate "consume typeahead" from a script (because all other reads are
blocking and wait for a newline).

On Dec 8,  4:01pm, Andrej Borsenkow wrote:
} Subject: RE: typeahead problem
}
} It is a "feature" of your particular OS. There is CLOBBERS_TYPEAHEAD define,
} that tries to correct this.

Unfortunately, CLOBBERS_TYPEAHEAD only applies when zle is setting up the
terminal with zsetterm(), which doesn't happen during getquery().

On Dec 8,  5:30pm, Andrej Borsenkow wrote:
} Subject: RE: typeahead problem
}
} I tried it here with 3.1.5 + patches. It looks, like ZSH takes the first
} character on the line and ignores the rest.
} 
} while read -q && sleep 10
} do
} echo YES
} done
} y <- cursor immediately springs to the next line
} yyyYES
}       ^^^ output by ZSH
} <- note newline
} YES
} 
} Only first 'y' from 'yyy' is taken. Is it what you've seen?

I see the following in a patched 3.0.5 and in both patched and unpatched
3.1.5:

zagzig% while read -q && sleep 5
while> do echo YES; done
y				<-- newline echoed immediately
yyyYES				<-- I typed yyy, YES echoed after 5 sec.
n				<-- echoed immediately after YES
zagzig% yyy			<-- typeahead now appears at the prompt

} Well, manual says "read -q reads only one character" so it is really
} confusing. Currently it "reads the line and takes the first character".
} Who's wrong - binary or manual?

On my system, at least, zsh does not consume the line, only the first y
of the four that I typed.  That agrees with the manual, except that the
manual doesn't discuss the typeahead behavior.

On Dec 8,  6:54pm, Andrej Borsenkow wrote:
} Subject: RE: typeahead problem
}
} The ultimate place to correct it is bin_read(); call
} getquery with last argument 1.

That would indeed change the behavior, but only when FIONREAD is supported.

On Dec 8,  6:39pm, Bernd Eggink wrote:
} Subject: Re: typeahead problem
}
} Hm, is there any reason to call getquery(x, 0) at all?

I think the choice to pass purge==0 was partly to get consistent script
behavior regardless of the availablilty of FIONREAD.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


  parent reply	other threads:[~1998-12-08 18:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-08 12:38 Bernd Eggink
1998-12-08 13:01 ` Andrej Borsenkow
1998-12-08 14:07   ` Bernd Eggink
1998-12-08 14:30     ` Andrej Borsenkow
1998-12-08 15:08       ` Bernd Eggink
1998-12-08 15:54         ` Andrej Borsenkow
1998-12-08 17:39           ` Bernd Eggink
1998-12-08 18:06           ` Bart Schaefer [this message]
1998-12-08 18:38             ` Andrej Borsenkow
1998-12-08 18:38             ` Bernd Eggink
1998-12-08 21:22               ` Bart Schaefer

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=981208100629.ZM6018@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=borsenkow.msk@sni.de \
    --cc=eggink@uni-hamburg.de \
    --cc=zsh-workers@math.gatech.edu \
    /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).