Skip to content

Commit

Permalink
process: add input method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayase-252 committed Mar 27, 2021
1 parent 924238d commit a585566
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/internal/bootstrap/switches/is_main_thread.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { ObjectDefineProperty } = primordials;
const { ObjectDefineProperty, FunctionPrototypeApply } = primordials;
const rawMethods = internalBinding('process_methods');

// TODO(joyeecheung): deprecate and remove these underscore methods
Expand Down Expand Up @@ -141,7 +141,7 @@ function getStderr() {
return stderr;
}

function getStdin() {
function getStdin () {
if (stdin) return stdin;
const fd = 0;

Expand Down Expand Up @@ -233,3 +233,19 @@ rawMethods.resetStdioForTesting = function() {
stdout = undefined;
stderr = undefined;
};


process.input = async function (...args) {
const utils = require("util")
const { createInterface } = require('readline')

const rl = createInterface({
input: process.stdin,
output: process.stdout
})

const res = await FunctionPrototypeApply(utils.promisify(rl.question), rl, args)
// Close Readline to avoid process hang
rl.close()
return res
}

0 comments on commit a585566

Please sign in to comment.