PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Get current cursor row as ASCII #
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Get current cursor row as ASCII #

Réponse
 
LinkBack Outils de la discussion
Vieux 17/05/2007, 21h41   #1
Hufnus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Get current cursor row as ASCII #

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

  Réponse avec citation
Vieux 18/05/2007, 08h59   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 19/05/2007, 03h19   #3
Hufnus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Get current cursor row as ASCII #

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


> 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

  Réponse avec citation
Vieux 20/05/2007, 11h51   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Get current cursor row as ASCII #

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h08.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10961 seconds with 12 queries