1827680 Members
3238 Online
109967 Solutions
New Discussion

Current cursor location

 
SAM_24
Frequent Advisor

Current cursor location

Hi,

Is there any way to find out current location of the cursor(I mean row & column) in a terminal? I learn from ITRC i can position the cursor using tput command. But I want to know it is possible to know current cursor location and.

Thanks.
Never quit
3 REPLIES 3
Mark Grant
Honored Contributor

Re: Current cursor location

This really really depends on your terminal. I remember some Wyse terminals would report the cursor position if sent the correct "escape" sequence.

I don't think there is a terminfo capability for reading a cursor position. However, you can "save" the cursor position with "tput sc" and then go back there sometime later with "tput rc". So if you are trying to read the cursor position in order to go back to where you started after doing some cursor positioning stuff, this might be the way to go.
Never preceed any demonstration with anything more predictive than "watch this"
Rodney Hills
Honored Contributor

Re: Current cursor location

Depending on the terminal type, you can usually send a status request escape sequence which can return the current cursor position. What you send and what is received are totally terminal dependent.

HTH

-- Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: Current cursor location

There is no terminfo sequence defined for this functtion. In general, it's not needed because there is a sequence 'mrcup' that works just like 'cup' except that for mrcup the commands are relative to the current current position rather than an absolute position. The bad news is that not all that many terminfo definitions have mrcup because it was really never needed for curses.
If it ain't broke, I can fix that.