Tuesday, 2 October 2018

node.js: readline: rl.write(data[, key])

rl.write(data[, key])
This method writes either data or a key sequence identified by key to the output. The key argument is supported only if output is a TTY text terminal.

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

/*
 * create a new readline.Interface instance that reads data from standard input
 * and write data to standard output
 */
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.write('Hello World');
rl.close();

Output
Hello World

Below table summarise the properties of key object.
Property
Type
Description
ctrl
boolean
true to indicate the <ctrl> key.
meta
boolean
true to indicate the <Meta> key.
shift
boolean
true to indicate the <Shift> key
name
string
The name of a key.

Note
a.   The key argument is supported only if output is a TTY text terminal.
b.   If key is specified, data is ignored.
c.   If the readline.Interface was created with output set to null or undefined the data and key are not written.
d.   rl.write() will resume the input stream if it has been paused.

HelloWorld.rs

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

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

console.log("Type something and press Ctrl + u to delete that line");

// Simulate Ctrl+u to delete the line written previously
rl.write(null, { ctrl: true, name: 'u' });




Previous                                                 Next                                                 Home

No comments:

Post a Comment