我正在编写一个非常简单的小型控制台应用程序,并且在玩一些ANSI转义序列以获得更好的输出.
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 ] -------------------------------------然后经过一些处理
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我尝试使用保存光标位置代码( ESC + [s )",然后使用 ESC + [u ,但是只会还原列,而不是行.
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.
在某些背景下,这是一个Node.JS程序.我已经简短地查看了 node-ncurses ,但是对于此任务来说似乎有点过头了(?)
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(?)
推荐答案当您在屏幕的最后一行中打印并且必须向下滚动时,会出现此问题.文本滚动不会更新保存的光标位置.您需要检测到发生了一些滚动(我不知道如何发生),并采取相应的操作,例如发送序列在Esc [u序列之后将光标向上移动以便移至原始位置.
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.
再见.-
更多推荐
ANSI转义序列:保存和恢复行位置
发布评论