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: Greg Wooledge
Subject: Re: [Help-bash] Storing cursor positions using tput into an array.
Date: Wed, 13 Sep 2017 08:40:58 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Sep 12, 2017 at 04:53:47PM -0500, Dennis Williamson wrote:
> On Tue, Sep 12, 2017 at 12:42 AM, Sinbad <address@hidden> wrote:
> > with, 'tput sc' and 'tput rc' I will be able to store only one cursor
> > position.
> > I want to be able to store multiple locations and return to those positions
> > accordingly.

> http://mywiki.wooledge.org/BashFAQ/006#Assigning_indirect.2Freference_variables

I don't see the need for that.  If he wants to store 10 cursor positions,
indexed by integers, then he only needs two arrays: x and y.

tput cup "${y[i]}" "${x[i]}"

Or call them "row" and "col" if you prefer.

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.



reply via email to

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