zsh-users
 help / color / mirror / code / Atom feed
* read -sq
@ 2021-02-21 16:41 Ray Andrews
  2021-02-21 17:31 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Ray Andrews @ 2021-02-21 16:41 UTC (permalink / raw)
  To: Zsh Users

If I use 'read -sq' and don't press 'y' (to do whatever), if the non 'y' 
key is some normal alphabetic key, it is not echoed to the terminal as 
'-s' indicates is correct, but if I use another key -- an arrow or DEL 
or END or one of those, it is echoed.  Can that be prevented?  Not a big 
deal but I use the down arrow to break back to a clean command line 
routinely so after a 'read -sq' I see " [B " on the command line.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: read -sq
  2021-02-21 16:41 read -sq Ray Andrews
@ 2021-02-21 17:31 ` Bart Schaefer
  2021-02-21 17:54   ` Ray Andrews
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2021-02-21 17:31 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Sun, Feb 21, 2021 at 8:42 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> If I use 'read -sq' and don't press 'y' (to do whatever), if the non 'y'
> key is some normal alphabetic key, it is not echoed to the terminal as
> '-s' indicates is correct, but if I use another key -- an arrow or DEL
> or END or one of those, it is echoed.  Can that be prevented?

Not really.  As the doc for -q says, "Read only one character from the
terminal", but the arrow keys actually send more than one character.
In the case of down-arrow those are ESC, bracket, and B, so read
consumes and discards the ESC and then whatever comes after it gets
the bracket and the B.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: read -sq
  2021-02-21 17:31 ` Bart Schaefer
@ 2021-02-21 17:54   ` Ray Andrews
  2021-02-21 21:00     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Ray Andrews @ 2021-02-21 17:54 UTC (permalink / raw)
  To: zsh-users

On 2021-02-21 9:31 a.m., Bart Schaefer wrote:
> Not really. As the doc for -q says, "Read only one character from the
> terminal", but the arrow keys actually send more than one character.
> In the case of down-arrow those are ESC, bracket, and B, so read
> consumes and discards the ESC and then whatever comes after it gets
> the bracket and the B.
Yeah, one keystroke is not the same as one character.  I wonder if you 
could
tell it to take whatever comes within an instant and treat that like one
character?  The ESC the braket and the B must come faster than anyone could
type, so clearly one keystroke, no?  Probably not worth the trouble I'll 
just
remind myself to hit the space for 'no'.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: read -sq
  2021-02-21 17:54   ` Ray Andrews
@ 2021-02-21 21:00     ` Bart Schaefer
  2021-02-21 21:58       ` Ray Andrews
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2021-02-21 21:00 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Sun, Feb 21, 2021 at 9:54 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Yeah, one keystroke is not the same as one character.  I wonder if you
> could tell it to take whatever comes within an instant and treat that like one
> character?

Depending on where/why you're using "read -q", you can potentially get
this effect by using "zle read-command" instead.

read-sq-init () {
  zle read-command
  BUFFER=${KEYS[1]}
  zle -U $'\n'
}
zle -N read-sq-init

read-sq () {
  : ${(P)${1:-REPLY}::=''}
  if zle
  then
    zle read-command
    : ${(P)${1:-REPLY}::=${KEYS[1]}}
  else
    vared -i read-sq-init ${1:-REPLY}
  fi
  if [[ ${(P)${1:-REPLY}} = [Yy] ]]
  then
    : ${(P)${1:-REPLY}::=y}
    return 0
  else
    : ${(P)${1:-REPLY}::=n}
    return 1
  fi
}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: read -sq
  2021-02-21 21:00     ` Bart Schaefer
@ 2021-02-21 21:58       ` Ray Andrews
  2021-02-21 23:03         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Ray Andrews @ 2021-02-21 21:58 UTC (permalink / raw)
  To: zsh-users

On 2021-02-21 1:00 p.m., Bart Schaefer wrote:
> Depending on where/why you're using "read -q", you can potentially get
> this effect by using "zle read-command" instead.
Thanks I'll take a look but I hafta admit:
...
>    : ${(P)${1:-REPLY}::=''}

Up to now the only time I've come across an exposed colon is in my nasty 
block comments
so this is fundamental syntax that I still don't understand.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: read -sq
  2021-02-21 21:58       ` Ray Andrews
@ 2021-02-21 23:03         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2021-02-21 23:03 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Sun, Feb 21, 2021 at 1:58 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> ...
> >    : ${(P)${1:-REPLY}::=''}
>
> this is fundamental syntax that I still don't understand.

Replace it everywhere with

typeset -g ${1:-REPLY}=whatever

if that makes it more readable.

You know what ${1:-REPLY} does, I presume.

${thing::=value} assigns value to $thing and substitutes value

${(P)thing} uses the value of thing as a variable name and retrieves
that variable

So ${(P)${1:-REPLY}::=''} is:
-- get $1 or if it isn't set use REPLY
-- retrieve the variable whose name that is
-- assign the empty string to that variable

Then the ":" command is merely to throw away the substituted result of ${...}.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-02-21 23:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-21 16:41 read -sq Ray Andrews
2021-02-21 17:31 ` Bart Schaefer
2021-02-21 17:54   ` Ray Andrews
2021-02-21 21:00     ` Bart Schaefer
2021-02-21 21:58       ` Ray Andrews
2021-02-21 23:03         ` Bart Schaefer

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).