I need to get my (Y, X) position of my terminal's cursor with the termcaps in C.
With ioctl()
i get the size of my terminal screen, but i still need to get where my cursor is.
I found this :
CSI 6 n DSR – Device Status Report Reports the cursor position to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column. (May not work on MS-DOS.)
But i have no idea how to use it in C ...
You write the command sequence (<ESC>[6n
) to the terminal using normal output to stdout
. Then you read the response using normal input from stdin
.
You need to parse the "reply" to pick out the position.