Saving and restoring the cursor position should be possible with simple ANSI escape sequences
ANSI escape sequences allow you to move the cursor around the screen at will. This is more useful for full screen user interfaces generated by shell scripts, but can also be used in prompts. The movement escape sequences are as follows:
- [...]
- Save cursor position:
\033[s
- Restore cursor position:
\033[u
However, it seems that this ANSI sequences restore only the horizontal position of the cursor. For example:
$ printf 'Doing some task...\e[s\n\nMore text\n\e[udone!\n\n\n'
Doing some task...
More text
done!
$
where the done!
is horizontally at the correct position but not vertically (correct in the sense of restored).
- Am I missing something, i.e. can you reproduce this?!
- Is this the intended desired behaviour? If so, how would I get the
done!
printed after thetask...
? - If this should not happen, might this behaviour be triggered indirectly by something in my environment?
I searched and read the many questions about, but I did not find anything about this behaviour I experienced. Actually, the same occur with tput
via
$ printf 'Doing some task...'; tput sc; printf '\n\nMore text\n'; tput rc; printf 'done!\n\n\n'
@gabor.zed
. I know about the issue, but it seems they don't.