Re: Get current cursor row as ASCII #
On Thu, 17 May 2007 12:41:35 -0800, Hufnus
<tonyb@sysdev.org> wrote:
>
>
> The only ANSI sequence, I know, that will report the numeric
> value of the current cursor position, in a BASH shell is:
>
> echo $'\e'[6n
>
> Unfortunately, the output is inside a returned escaped sequence,
> intended to be piped to say cat or echo -ne... This sequence
> could then be piped or echo'ed to execute the ansi positioning.
>
> There appears to be no way that the embedded row position
> returned can be piped to a script variable, so the I can save it
> for future positioning use.
>
> I can not use the ANSI cursor save & restore sequences,
> because its a busy script creating text shell color dialog boxes
> which accept user 'press a key' [Ok] [Cancel] responses.
>
> Is there a way that I can extract the current shell cursor Row
> as a integer into a bash variable?
>
> Thanks for any suggestions
> TonyB
>
stty -echo; echo -n $'\e[6n'; read -d R x; stty echo; echo ${x#??}
"read -d" works in bash or zsh; see the manual for other shells.
I would use tput instead of echo, but terminfo doesn't seem to have a
name for the \e[6n sequence.
--
No stopping or standing.
|