node.js stdout clearline() and cursorTo() functions

前端 未结 5 1969
没有蜡笔的小新
没有蜡笔的小新 2020-12-25 12:11

From a node.js tutorial, I see those two process.stdout functions :

process.stdout.clearLine();
process.stdout.cursorTo(0);

But I\'m using

5条回答
  •  有刺的猬
    2020-12-25 12:48

    This is the solution :

    First, require readline :

    var readline = require('readline');
    

    Then, use cursorTo like this :

    function writeWaitingPercent(p) {
        //readline.clearLine(process.stdout);
        readline.cursorTo(process.stdout, 0);
        process.stdout.write(`waiting ... ${p}%`);
    }
    

    I've commented clearLine, since it's useless in my case (cursorTo move back the cursor to the start)

提交回复
热议问题