Tuesday 2 October 2018

node.js: readline.cursorTo(stream, x, y)

readline.cursorTo(stream, x, y)
This method moves cursor to the specified position in a 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.cursorTo(process.stdout, 0, 0);
 
 total_interval_time += interval_time_out;
 
 rl.write("Total time : " + total_interval_time);

}, interval_time_out);



Previous                                                 Next                                                 Home

No comments:

Post a Comment