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

Re: read -sq



On Sun, Feb 21, 2021 at 9:54 AM Ray Andrews <rayandrews@xxxxxxxxxxx> 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
}




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