Skip to content

Instantly share code, notes, and snippets.

@Densyakun
Last active December 5, 2022 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Densyakun/11eb9ae66bdee6fd6e39a7dbad50f8ff to your computer and use it in GitHub Desktop.
Save Densyakun/11eb9ae66bdee6fd6e39a7dbad50f8ff to your computer and use it in GitHub Desktop.
import { createInterface } from "readline"
import { promisify } from "util"
const rl = createInterface({
input: process.stdin,
output: process.stdout
})
const question = promisify<string, string>(rl.question as (answer: string) => Promise<string>).bind(rl)
async function questionAndAnswer() {
// Wait to receive data on the input stream.
let answer = ""
while (answer !== "y" && answer !== "n") {
answer = (await question('(Y/N)? '))
if (answer.length) answer = answer[0].toLowerCase()
}
if (answer === "y") {
//
} else if (answer === "n") {
//
}
rl.close()
}
questionAndAnswer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment