ANSI escape sequences: save and restore a row position

☆樱花仙子☆ 提交于 2021-02-07 17:23:15

问题


I'm writing a very simple little console application and I'm playing around with some ANSI escape sequences to get some nicer output.

What I'm trying to do is something like this. There's a header with a name, and then underneath, as the program runs, several lines are printed. As each line is printed, I'd like to update the header row with a progress meter. 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've tried using the save cursor position code (ESC + [s) and then restoring that position with ESC + [u, however that only restores the column, not the row.

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


回答1:


This is a problem arising when you are printing in the last row of the screen and it has to scroll down. The scroll of the text do not update the saved cursor position. You need to detect that some scroll happend (I don't know how) and take the corresponding action like send sequences moving the cursor up after the Esc[u sequence in order to go to the original position.

Bye.-



来源:https://stackoverflow.com/questions/7465726/ansi-escape-sequences-save-and-restore-a-row-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!