| Stephane CHAZELAS 2007-10-24, 7:31 am |
| 2007-10-24, 03:37(-04), Chris F.A. Johnson:
> On 2007-10-24, Markus Mayer wrote:
>
> I use this shell function:
>
> _curpos()
> {
> stty -echo;
> printf '\e[6n';
> read -d R _CURPOS;
> stty echo;
> _CURPOS=${_CURPOS#??};
> _CURX=${_CURPOS#*;};
> _CURY=${_CURPOS%;*}
> }
[...]
Note that read -d is zsh/bash/ksh93 specific (and you need
recent versions). With ksh93 (at least the ksh93s+ I have access
to), it doesn't work, it does seem to disable the cooked mode like
the other shells, but you still need to enter a newline
character (via <Ctrl-J>!), for read to return.
Portably, you can use dd, either by reading one character at a
time until you find "R" or using the terminal timeout as in my
suggestion.
Also, the local echo might already be disabled before the call
to _curpos, so you may want to not do a stty echo afterwards but
instead to save the settings and restore them afterwards.
In zsh:
STTY=-echo read -dR $'_CURPOS?\e[6n'
--
Stéphane
|