Last active
February 27, 2019 04:48
-
-
Save leontastic/7f768bca98a0b5fc39ab0aac4a5d1a13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ask your user questions on the command line in sequence | |
import readline from "readline"; | |
let answer: Promise<string>; | |
const askQuestion = (question: string) => | |
new Promise<string>(resolve => { | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.question(`${question}`, answer => { | |
rl.close(); | |
resolve(answer); | |
}); | |
}); | |
const prompt = (question: string) => { | |
if (answer) answer = answer.then(() => askQuestion(question)); | |
else answer = askQuestion(question); | |
return answer; | |
}; | |
export default prompt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment