← Back to context

Comment by pherrephatta

6 years ago

You can look at the programmer's guide for the VT100[1], which does a good job of explaining the different ANSI escape codes.

To put it simply, you can move the cursor down and to the right. For example, you'd move the cursor 999 lines down, then 999 columns to the right, and then query the cursor's position[2]. You can then read the output through STDOUT and parse it.

I'd recommend anyone who's interested in playing around with ANSI and learning how to write a pure terminal-based program to look into the Kilo text editor[3]. That's where I learnt the above instructions.

[1] https://vt100.net/docs/vt100-ug/chapter3.html

[2] https://vt100.net/docs/vt100-ug/chapter3.html#CPR

[3] https://viewsourcecode.org/snaptoken/kilo/