1834053 Members
2466 Online
110063 Solutions
New Discussion

Re: Cursor

 
SOLVED
Go to solution
SAM_24
Frequent Advisor

Cursor

Hi,

You might have seen during some installation we will get message "Please wait" till the installation is completed. Any idea what is the logic behind the cursor rotation? I want to to include it in my script.

Thanks.
Never quit
2 REPLIES 2
Mark Grant
Honored Contributor

Re: Cursor

I would guess its very simple and goes something like this.

|/-\| etc etc.

Just have this in a loop with a sleep.

Before this bit of code "trap" SIGCHLD. Do your work in the background and when your work has finished, you handle the SIGCHLD signal to get out of your loop.
Never preceed any demonstration with anything more predictive than "watch this"
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Cursor

One of the fundmental principles of UNIX coding is to make sure that you never hardcode sequences to position the cursor. Instead, ask the terminfo database how to do something.

In this case, the trick is to store the sequence for a particular screen location, "tput cup row col" does this.



spin()
{
typeset -i10 ROW=${1}
typeset -i10 COL=${2}
shift 2
typeset CUP=$(tput cup ${ROW} ${COL})
typeset A[0]="|"
typeset A[1]="/"
typeset A[2]="+"
typeset A[3]="\\"
typeset -i10 I=0
while [[ ${I} -lt 12 ]]
do
echo "${CUP}${A[$((${I} % 4))]}${CUP}\c"
((I += 1))
sleep 1
done
return 0
} # spin

tput clear
spin 5 10

------------------------------
This should get you started.

If it ain't broke, I can fix that.