Node.js:阻止游标包装

时间:2016-01-09 10:57:30

标签: javascript node.js terminal newline ansi

使用process.stdout.write,光标将留在您输出的字符串的末尾 但是,当您在终端的右边界上写任何内容时,光标将放在下一行的开头。

如果您希望通过填充整个终端为应用程序提供背景,则会出现问题,因为它会滚动窗口。

有一种解决方法,在写入右下角字符插槽后向后滚动一行,但这似乎并不适用于所有平台,即cmd。

1 个答案:

答案 0 :(得分:0)

从描述中,您似乎在谈论ansi.js,其中(如ANSI escape sequences aren't printed to stdout on Windows中的accepted answer所述)依赖于libuv等库。< / p>

该库实现了适量的转义序列。但是参考source-code for ansi.js,它使用 escape [ S 作为向上滚动功能。该转义序列不由libuv处理。

libuv中的comment解释了原因:

 * Normally cursor movement in windows is relative to the console screen buffer,
 * e.g. the application is allowed to overwrite the 'history'. This is very
 * inconvenient, it makes absolute cursor movement pretty useless. There is
 * also the concept of 'client rect' which is defined by the actual size of
 * the console window and the scroll position of the screen buffer, but it's
 * very volatile because it changes when the user scrolls.

在curses应用程序中,通过在倒数第二列中编写右下角的字符,然后使用insert-character将其放置到位来完成此类操作。但ansi.jslibuv都没有实现这一点。

相关问题