|
Home > Archive > Unix Shell > May 2007 > Get current cursor row as ASCII #
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Get current cursor row as ASCII #
|
|
| Hufnus 2007-05-17, 7:18 pm |
| 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
There are 10 types of people in this world, those that read
binary and those who don't!
--
__ __ _ I N C. http://www.sysdev.org
/ __|\\// __|| \ __ __ / tonyb@sysdev.org
\__ \ \/\__ \||)|/ O_)\/ / \/ System Tools / Utilities
|___/ || ___/|_ /\___|\_/ WIntel / Linux Device Drivers
| |
| Bill Marcum 2007-05-18, 7:20 am |
| 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.
| |
| Hufnus 2007-05-19, 1:20 am |
| On Fri, 18 May 2007 07:59:58 GMT
Bill Marcum <marcumbill@bellsouth.net> wrote:
> On Thu, 17 May 2007 12:41:35 -0800, Hufnus
> <tonyb@sysdev.org> wrote:
[vbcol=seagreen]
> stty -echo; echo -n $'\e[6n'; read -d R x; stty echo; echo
> ${x#??}
Thank you Bill, that worked for me after I manipulated your
sequence some more as listed below, to actually extract row and
col as usable script vars:
i=0
j=0
row=""
delim=""
stty -echo
echo -n $'\e[6n'
read -d R x
stty echo
field=`echo ${x#??}`
while [ ! "$delim" = ";" -a $i -lt 12 ]; do
delim=${field:i:1}
i=`expr $i + 1`
done
i=`expr $i - 1`
row=${field:0:i}
i=`expr $i + 1`
j=`expr $i + 1`
while [ ! "$delim" = ";" -a $j -lt 6 ]; do
delim=${field:j:1}
j=`expr $j + 1`
done
col=${field:i:j}
echo X \<\- row=$row col=$col
thxs
TonyB
There are 10 types of people in this world, those that read
binary and those who don't!
--
__ __ _ I N C. http://www.sysdev.org
/ __|\\// __|| \ __ __ / tonyb@sysdev.org
\__ \ \/\__ \||)|/ O_)\/ / \/ System Tools / Utilities
|___/ || ___/|_ /\___|\_/ WIntel / Linux Device Drivers
| |
| Stephane CHAZELAS 2007-05-20, 7:19 am |
| 2007-05-18, 07:59(+00), Bill Marcum:
[...]
> 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.
[...]
It's sometimes found in u7.
$ tput u7 | od -c
0000000 033 [ 6 n
0000004
--
Stéphane
|
|
|
|
|