(prompt: string)
| 5 | * Properly handles backspace and Ctrl+C |
| 6 | */ |
| 7 | export function question(prompt: string): Promise<string> { |
| 8 | return new Promise((resolve) => { |
| 9 | const rl = readline.createInterface({ |
| 10 | input: process.stdin, |
| 11 | output: process.stdout, |
| 12 | terminal: true, |
| 13 | }); |
| 14 | |
| 15 | // Handle Ctrl+C properly |
| 16 | rl.on("SIGINT", () => { |
| 17 | console.log("\n"); |
| 18 | rl.close(); |
| 19 | process.exit(0); |
| 20 | }); |
| 21 | |
| 22 | rl.question(prompt, (answer) => { |
| 23 | rl.close(); |
| 24 | resolve(answer); |
| 25 | }); |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Creates a prompt with limited choices |
no test coverage detected