prompt.ts 356 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import readline from 'readline'

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

export const prompt = (msg: string) =>
  new Promise<void>((resolve, reject) =>
    rl.question(`${msg} [y/n]: `, (confirmation) => {
      if (confirmation !== 'y') {
        reject('Aborted!')
      }

      resolve()
    })
  )