I'm trying to retrieve the coordinates of cursor in a VT100 terminal using the following code:
void getCursor(int* x, int* y) {
printf("\033[6n");
scanf("\033[%d;%dR", x, y);
}
I'm using the following ANSI escape sequence:
Device Status Report - ESC[6n
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.
The code compiles and the ANSI sequence is sent, but, upon receiving it, the terminal prints the ^[[x;yR
string to the stdout
instead of stdin
making it imposible for me to retrieve it from the program:
Clearly, the string is designated for the program, though, so I must be doing something incorrectly. Does anybody know what it is?
^[[x;yR
to the terminal at all? I'd like to silently retrieve the coordinates without any visible change to the terminal screen. But this writes to the terminal (undesirable when creating a textual GUI) and thus changes the coordinates of the cursor (which makes it absolutely useless). – Hartsock