Tuesday, 2 October 2018

node.js: readline.moveCursor(stream, dx, dy)

readline.moveCursor(stream, dx, dy)
This method moves the cursor relative to its current position in a given TTY stream.

HelloWorld.js
/* Import readline module */
var readline = require('readline');

var interval_time_out = 500;
var total_interval_time = 0;

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout);

/* Repeat this function for every 500 milliseconds */
var intervalRef = setInterval(function(){
 //readline.clearLine(process.stdout, 0);
 readline.moveCursor(process.stdout, 1, 1);
 
 total_interval_time += interval_time_out;
 
 rl.write("Total time : " + total_interval_time);

}, interval_time_out);


It prints output like below.

Total time : 500
                  Total time : 1000
                                    Total time : 1500
                                                      Total time : 2000
                                                                        Total time : 2500
                                                                                          Total time : 3000
                           ......



Previous                                                 Next                                                 Home

No comments:

Post a Comment