Search code examples
haskellterminalcursor-positionansi-escape

`ansi-terminal` how to get cursor position in Haskell


The ansi-terminal library is a wonderful little library that allows you to move the cursor around and stuff (without all the extra stuff ncurses based stuff imposes.) The only problem is it doesn't provide a way to get the position of the cursor. Anyway, that uses or is compatible with the rest of the library, that I could do that. I know one way would be to track the cursor everywhere it goes, but I want to allow outside putStrs and such.


Solution

  • According to Wikipedia, the DSR terminal command should get you the position, and there are also commands to save and restore the position. I don't know why ansi-terminal does not support these; perhaps you should file a bug report.

    UPDATE: Support for saving and restoring cursor position has now been added to ansi-terminal!