I am playing with some terminal capabilities to create async prompt output on bash
. I want to get something like this: while outputting string in PROMPT_COMMAND
, save terminal cursor position, print put ...
and go do other stuff (printing other info for example); then some time later go back to memorized position and print something new. PS1
is designed that way that command itself is put on newline, so that async output is just text in terminal.
I found out cup
terminfo entry to move cursor to given position, an there are escape codes to get current position (for examble, see this question). But for me, seems like all of them work with cursor position on screen, rather than in terminal buffer. That means that after putting new line my remembered position will be wrong.
Are there any way to work with terminal cursor position to store and restore cursor position based on buffer position? You can assume that the remembered position is still in visible part of the buffer (so you actually can put cursor there), but it might go up several lines up. For now, let's not consider race conditions. If no, I will try to find other tricks.
There is zsh
shell which actually has async prompt support, but I don't actually know will it work if before output user will press Enter to go to new line.
PS1
...