Tuesday 2 October 2018

node.js: readline.clearLine(stream, dir)

readline.clearLine(stream, dir)
method clears current line of given TTY stream in a specified direction identified by dir.

Argument ‘dir’ represents the direction.
dir value
Description
-1
to the left from cursor
1
to the right from cursor
0
the entire line

Find the below working application.

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