help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Storing cursor positions using tput into an array.


From: Bob Proulx
Subject: Re: [Help-bash] Storing cursor positions using tput into an array.
Date: Thu, 14 Sep 2017 12:26:35 -0600
User-agent: NeoMutt/20170609 (1.8.3)

Greg Wooledge wrote:
> The real voodoo is how to GET the cursor position into the coordinate
> arrays in the first place.  Starting from
> 
> https://unix.stackexchange.com/questions/88296/get-vertical-cursor-position/183121#183121
> 
> I ended up with:
> 
> wooledg:~$ IFS=$'\e[;' read -sdR -p $'\e[6n' _ _ 'y[1]' 'x[1]'
> wooledg:~$ declare -p x y
> declare -a x=([1]="1")
> declare -a y=([1]="45")
> 
> Not tested on anything but my own system in one terminal emulator.
> Use at your own risk, etc.

Yes.  Getting the cursor position seems to be voodoo.  Unfortunately
using \e escape hard codes for one terminal type.  The above is the
popular one today but it won't work for other types such as say
hpterm.  (I didn't test hpterm but I assume not.)  But I haven't found
a better way to ge tthis info either.

I think the original plan was that if some application wanted to
position the cursor then that application must position and track the
position itself completely.  Like the way the curses library does it.
Then it will know where the cursor is later because it placed the
cursor there, obviating the need to ask the terminal where the cursor
happens to be at the moment.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]