12345678910111213141516171819202122232425 |
- // source: https://stackoverflow.com/a/46488389
- //
- var question = function(q) {
- return new Promise( (res, rej) => {
- const stdin_proc = process.openStdin()
- process.stdout.write(q)
- function catchInput(text) {
- const ans = text.toString().trim()
- res(ans);
- stdin_proc.pause(); // stop reading
- }
- // We use once to avoid "MaxListenersExceededWarning" error
- stdin_proc.once('data', catchInput);
- });
- };
- //
- (async function main() {
- var answer;
- while ( answer != 'yes' ) {
- answer = await question('Are you sure? ');
- }
- console.log( 'finally you are sure!');
- })();
|