ANSI转义序列:保存和恢复行位置

编程入门 行业动态 更新时间:2024-10-14 12:27:50
本文介绍了ANSI转义序列:保存和恢复行位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个非常简单的小型控制台应用程序,并且在玩一些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转义序列:保存和恢复行位置

本文发布于:2023-10-08 15:08:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472987.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   位置   ANSI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!