Using ANSI escape sequences, I would like to find the current location of the cursor in the terminal/screen/window.
To move the cursor to the 5th row, 3rd column of the screen/terminal/window, I could use this statement:
print!("\x1B[{};{}H", 5, 3);
(followed by a flush if needed -- io::stdout().flush().unwrap();
. I could use println!()
, but that'll move the cursor.)
If I want to know where the cursor is currently located, I could use this statement:
print!("\x1B[6n"];
which will print to the terminal/screen a result like this:
^[[5;3R
How can I capture that output into a variable (for further processing into an eventual x=3, Y=5 result)?