Sinbad
2017-09-11 12:54:16 UTC
Hi,
I want to extract the cursor positions using tput into an array and recover
to the stored cursor positions accordingly at later point in time. The
following function is able to extract the position
but i'm not able to figure out how to store each extraction in to an array.
save_pos () {
export $1
exec < /dev/tty
oldstty=$(stty -g)
stty raw -echo min 0
echo -en "\033[6n" > /dev/tty
IFS=';' read -r -d R -a pos
stty $oldstty
eval "$1[0]=$((${pos[0]:2} - 2))"
eval "$1[1]=$((${pos[1]} - 1))"}
save_pos pos works, But i want something like save_pos pos[$index];
but this is resulting into
an error. how to achieve this ?
Thanks
I want to extract the cursor positions using tput into an array and recover
to the stored cursor positions accordingly at later point in time. The
following function is able to extract the position
but i'm not able to figure out how to store each extraction in to an array.
save_pos () {
export $1
exec < /dev/tty
oldstty=$(stty -g)
stty raw -echo min 0
echo -en "\033[6n" > /dev/tty
IFS=';' read -r -d R -a pos
stty $oldstty
eval "$1[0]=$((${pos[0]:2} - 2))"
eval "$1[1]=$((${pos[1]} - 1))"}
save_pos pos works, But i want something like save_pos pos[$index];
but this is resulting into
an error. how to achieve this ?
Thanks