清除 NodeJS 流中的所有行 [英] Clear all lines in NodeJS stream
本文介绍了清除 NodeJS 流中的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
process.stdout.clearLine()
删除最新行.如何删除 stdout
中的所有行?
process.stdout.clearLine()
deletes latest line. How can I delete all lines from stdout
?
var out = process.stdout;
out.write("1\n"); // prints `1` and new line
out.write("2"); // prints `2`
setTimeout(function () {
process.stdout.clearLine(); // clears the latest line (`2`)
out.cursorTo(0); // moves the cursor at the beginning of line
out.write("3"); // prints `3`
out.write("\n4"); // prints new line and `4`
console.log();
}, 1000);
输出为:
1
3
4
我想从 stdout
中删除所有行而不是最新行,所以输出将是:
I want to delete all lines from stdout
instead of latest line, so the output will be:
3
4
推荐答案
不知道这是否有助于您尝试此代码:
dont know if this helps you try this code:
var out = process.stdout;
var numOfLinesToClear = 0;
out.write("1\n"); // prints `1` and new line
++numOfLinesToClear;
out.write("2\n");
++numOfLinesToClear;
process.stdout.moveCursor(0,-numOfLinesToClear); //move the cursor to first line
setTimeout(function () {
process.stdout.clearLine();
out.cursorTo(0); // moves the cursor at the beginning of line
out.write("3"); // prints `3`
out.write("\n4"); // prints new line and `4`
console.log();
}, 1000);
这篇关于清除 NodeJS 流中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文