如何使用 Node.JS 编辑当前以上的控制台行?
How to edit console line above current with Node.JS?
目前,我正在编辑一行。
const editLine = (data) => {
process.stdout.clearLine();
process.stdout.write(`\r${data}`);
};
// Call editLine() whenever there is new data to log on that line
假设我们有这样一个函数。它编辑光标当前所在的任何行。但是,假设我们做这样的事情...
console.log('Hi');
console.log('There');
有什么办法可以编辑“你好”那一行吗?目前,我只知道使用 Node.JS 编辑当前行的方法。是否可以使用 Node 编辑光标当前不在的行?我在那里看到了一些非常漂亮的控制台图形,但我确定大多数不是用 Node.JS.
编写的
如有任何帮助,我们将不胜感激。
您可以使用 clearLine 和 cursorTo 执行类似的操作:
process.stdout.write("Something to be replaced");
process.stdout.clearLine();
process.stdout.cursorTo(0);
// continue writing from here...
目前,我正在编辑一行。
const editLine = (data) => {
process.stdout.clearLine();
process.stdout.write(`\r${data}`);
};
// Call editLine() whenever there is new data to log on that line
假设我们有这样一个函数。它编辑光标当前所在的任何行。但是,假设我们做这样的事情...
console.log('Hi');
console.log('There');
有什么办法可以编辑“你好”那一行吗?目前,我只知道使用 Node.JS 编辑当前行的方法。是否可以使用 Node 编辑光标当前不在的行?我在那里看到了一些非常漂亮的控制台图形,但我确定大多数不是用 Node.JS.
编写的如有任何帮助,我们将不胜感激。
您可以使用 clearLine 和 cursorTo 执行类似的操作:
process.stdout.write("Something to be replaced");
process.stdout.clearLine();
process.stdout.cursorTo(0);
// continue writing from here...