I want to get the cursor\'s position in a terminal window. I know I can echo -e \"\\033[6n\"
and read
the output -s
silently as in thi
Here we go -you can simply read sys.stdout
yourself to get the value.
I found the answer in a question just like yours, but for one trying to do that from a C program:
http://www.linuxquestions.org/questions/programming-9/get-cursor-position-in-c-947833/
So, when I tried something along that from the Python interactive terminal:
>>> import sys
>>> sys.stdout.write("\x1b[6n");a=sys.stdin.read(10)
]^[[46;1R
>>>
>>> a
'\x1b[46;1R'
>>> sys.stdin.isatty()
True
You will have to use other ANSI tricks/position/reprint to avoid the output actually showing up on the terminal, and prevent blocking on stdin read - but I think it can be done with some trial and error.