30 lines
659 B
TypeScript
30 lines
659 B
TypeScript
import * as readline from 'readline'
|
|
|
|
export async function confirm(message: string): Promise<boolean> {
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
})
|
|
|
|
return new Promise((resolve) => {
|
|
rl.question(`${message} [y/N] `, (answer) => {
|
|
rl.close()
|
|
resolve(answer.toLowerCase() === 'y')
|
|
})
|
|
})
|
|
}
|
|
|
|
export async function prompt(message: string): Promise<string> {
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
})
|
|
|
|
return new Promise(resolve => {
|
|
rl.question(message, (answer) => {
|
|
rl.close()
|
|
resolve(answer)
|
|
})
|
|
})
|
|
}
|