ANSI escape sequences: saving and restoring line position

I am writing a very simple little console application, and I play with some ANSI escape sequences to get a more pleasant result.

What I'm trying to do is something like this. There is a title with a name, and then below it, as the program starts, several lines are printed. When each line is printed, I want to update the title bar with a progress bar. eg:

My header row [ 0/5 ] ------------------------------------- 

then after some processing

 My header row [ 1/5 ] ------------------------------------- here is some output 

...

 My header row [ 2/5 ] ------------------------------------- here is some output the output could be over several lines 

I tried to use the save cursor position code ( ESC + [s ) and then restore that position with ESC + [u , however this only restores the columns not lines.

for some background, this is the Node.JS program. I briefly looked at node-ncurses , however this seems a bit overkill for this task (?)

+4
source share
1 answer

This is a problem that occurs when printing on the last line of the screen, and it should scroll down. Scrolling text does not update the saved cursor position. You need to find that some scrolls occur (I don’t know how) and take appropriate actions, such as send sequences, moving the cursor up after the Esc [u sequence to go back to the starting position.

Bye.-

+4
source

All Articles