How to use the createInterface function from readline
Find comprehensive JavaScript readline.createInterface code examples handpicked from public code repositorys.
readline.createInterface is a function that creates a new interface for reading input from a readable stream, such as a user's command-line input.
324 325 326 327 328 329 330 331 332 333
}, _parseGeoNamesAlternateNamesCsv: function (pathToCsv, callback) { var that = this; that._alternateNames = {}; var lineReader = readline.createInterface({ input: fs.createReadStream(pathToCsv), }); lineReader.on('line', function (line) { line = line.split('\t');
+ 3 other calls in file
GitHub: FKLC/WhatsAppToDiscord
485 486 487 488 489 490 491 492 493 494 495
}; const ui = { async input(query) { return new Promise((resolve) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.question(query, (answer) => {
+ 3 other calls in file
How does readline.createInterface work?
readline.createInterface
is a function provided by the Node.js readline
module that allows you to read input from a user through a command line interface.
When readline.createInterface
is called, it takes in an object with properties specifying the input and output streams to use for the interface.
Once the interface is created, you can use its question
method to prompt the user for input and receive the user's response.
The readline
module is often used for creating command-line interfaces for Node.js applications, and can be useful for building interactive command-line tools and utilities.
196 197 198 199 200 201 202 203 204 205
if (revisionAge < 2) { logger.logWarning(`Revision Age is ${revisionAge}; currently processing jobs will be removed when revision age is set to 0.`); if (!force) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const response = await new Promise((resolve) => rl.question('Continue? (y/N): ', (ans) => { rl.close(); resolve(ans); }));
218 219 220 221 222 223 224 225 226 227
}) const rlout = new PassThrough() rlout.pipe(output, { end: false }) const rli = rl.createInterface(rlin, rlout) try { while (true) { /** * @type {string}
Ai Example
1 2 3 4 5 6 7 8 9 10 11
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.question("What is your name? ", (name) => { console.log(`Hello, ${name}!`); rl.close(); });
In this example, we're using readline.createInterface to create a new interface for reading input from the process.stdin and process.stdout streams. We're then using the question method to prompt the user for input with the message "What is your name?" and receive the user's response as the name parameter in the callback function. Finally, we're using console.log to output a personalized greeting to the user, and the rl.close() method to close the interface and exit the program. When we run this code, we get the following output: csharp Copy code
GitHub: rooklift/ogatak
171 172 173 174 175 176 177 178 179 180
this.exe.stdin.once("error", (err) => { this.log_and_alert("Got exe.stdin error:", err.toString()); this.shutdown(); }); this.scanner = readline.createInterface({ input: this.exe.stdout, output: undefined, terminal: false });
+ 7 other calls in file
130 131 132 133 134 135 136 137 138 139 140
const prompt = async (question, onlyMainnet = true) => { if (onlyMainnet && hre.network.name != 'mainnet') { return; } const r = rl.createInterface({ input: process.stdin, output: process.stdout, terminal: false });
GitHub: BuilderIO/qwik-build
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
changeValue() { this.value = this._value.value; } }; function aD({ input: t = import_node_process.stdin, output: u2 = import_node_process.stdout, overwrite: F2 = true, hideCursor: e2 = true } = {}) { const s = f.createInterface({ input: t, output: u2, prompt: "", tabSize: 1 }); f.emitKeypressEvents(t, s), t.isTTY && t.setRawMode(true); const C2 = (D2, { name: i }) => { if (String(D2) === "" && process.exit(0), !F2) return;
+ 3 other calls in file
GitHub: RyderL/Wargame-RCON
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
} const loadLog = async function(host, dir) { const stream = fs.createReadStream(dir + '/serverlog.txt'); const readLine = readline.createInterface({ input: stream, crlfDelay: Infinity });
+ 2 other calls in file
GitHub: roroiii/LidemyOJ
6 7 8 9 10 11 12 13 14 15 16 17 18
*/ var readline = require("readline"); var lines = []; var rl = readline.createInterface({ input: process.stdin, }); rl.on("line", function (line) {
9 10 11 12 13 14 15 16 17
this.ticTacToeLayout = ''; this.currentPlayer = false; // player 1 = false (O), player 2 = true (X) this.gameEnded = false; this.moveRegister = []; this.rl = readline.createInterface({ input: process.stdin, output: process.stdout })
+ 3 other calls in file
GitHub: theriex/digger
192 193 194 195 196 197 198 199 200 201
console.log(crash.stack); //defined for Error object exceptions console.log("--------"); console.log("It would be greatly appreciated if you would copy the above info and mail it to support@diggerhub.com"); //the console window immediately disappears on windows. Prompt to //hold it open so the user has a chance to read and email the err. const rl = readline.createInterface({input: process.stdin, output: process.stdout}); rl.question("\n", function (ignore) { process.exit(1); }); }
GitHub: noslate-project/aworker
179 180 181 182 183 184 185 186 187 188
console.error('[wpt] httpd exited with', code, signal); } this.wptHttpd = null; }); const rl = readline.createInterface(this.wptHttpd.stderr); rl.on('line', line => { if (line.startsWith('DEBUG')) { return; }
115 116 117 118 119 120 121 122 123 124 125
/* * Parse `key=value` lines from stdin until EOF or the first blank line. */ function parse() { return new Promise((resolve, reject) => { const rl = readline.createInterface({input: process.stdin}); let resolved = false; const query = {};
12 13 14 15 16 17 18 19 20 21 22
class UI { constructor(opt) { // Instantiate the Readline interface // @Note: Don't reassign if already present (allow test to override the Stream) if (!this.rl) { this.rl = readline.createInterface(setupReadlineOptions(opt)); } this.rl.resume();
63 64 65 66 67 68 69 70 71 72 73
console.log(commands[command].description); console.log(commands[command].usage ? `usage:\n${commands[command].usage}` : ''); } }; const HBNBCommand = readline.createInterface({ input: process.stdin, output: process.stdout });
37 38 39 40 41 42 43 44 45 46
const path = '/opt/dcloud/demo-automation/.env' const text = fs.readFileSync(path, 'utf-8') const lines = text.split('\n') // const fileStream = fs.createReadStream('/opt/dcloud/demo-automation/.env') // const lines = readline.createInterface({ // input: fileStream, // crlfDelay: Infinity // }) // Note: we use the crlfDelay option to recognize all instances of CR LF
80 81 82 83 84 85 86 87 88 89
}); } ///------------------------------------ function convertOriginalCSV() { const stream = fs.createReadStream("../audibleBookData.csv"); const rl = readline.createInterface({ input: stream }); let data = []; rl.on("line", (row) => { data.push(row.split(",")); });
85 86 87 88 89 90 91 92 93 94
if ('srt' != fileInfo.extension.toLowerCase()) { throw new Error(`El fichero ${path} no es un subtítulo`); } const temporary = `${fileInfo.parent}/${fileInfo.name}.tmp`; const lineReader = readline.createInterface({ input: fs.createReadStream(path, {encoding: 'binary'}) }); const output = fs.createWriteStream(temporary, {encoding: 'binary'});
+ 4 other calls in file
GitHub: meringlab/paxdb-api
144 145 146 147 148 149 150 151 152 153
if (!(species in proteinsCovered)) { proteinsCovered[species] = new Set(); } datasets[species].push(dataset); const input = fs.createReadStream(`./data/abundances/${d}`); const rl = readline.createInterface({ input }) rl.on('close', function () { //add ranks var abundancesSorted = []
GitHub: amavr/sio-adapter
111 112 113 114 115 116 117 118 119 120
} static async processLineByLine(filePath, onLine) { const instream = fs.createReadStream(filePath); const outstream = new stream; const rl = readline.createInterface(instream, outstream); const fname = path.parse(filePath).base; let line = 0 for await (const s of rl) {
+ 11 other calls in file
readline.createInterface is the most popular function in readline (187 examples)