Tuesday 2 October 2018

process.stdout clearLine() and cursorTo methods

cursorTo() method moves cursor to the specified position in a given TTY stream.

clearLine() method clears current line of given TTY stream.

Find the below working example.

HelloWorld.js

var interval_time_out = 500;
var total_interval_time = 0;

var intervalRef = setInterval(function(){
 process.stdout.clearLine();
 process.stdout.cursorTo(0);
 
 total_interval_time += interval_time_out;
 
 process.stdout.write("Total time : " + total_interval_time);

}, interval_time_out);

When you ran above application, you can see total time is updated in the same line. It is because, I am calling clearLine, moving the cursor to 0th line and print the information for every interval.






Previous                                                 Next                                                 Home

No comments:

Post a Comment