* Prompt for text input using readline. * * @param prompt - The prompt text to display * @returns The user's input * @throws If input is cancelled or an error occurs
(prompt: string)
| 99 | * @throws If input is cancelled or an error occurs |
| 100 | */ |
| 101 | async promptForInput(prompt: string): Promise<string> { |
| 102 | return new Promise((resolve, reject) => { |
| 103 | this.beforePrompt() |
| 104 | this.isPrompting = true |
| 105 | |
| 106 | const rl = readline.createInterface({ |
| 107 | input: this.stdin, |
| 108 | output: this.stdout, |
| 109 | }) |
| 110 | |
| 111 | rl.question(prompt, (answer) => { |
| 112 | rl.close() |
| 113 | this.isPrompting = false |
| 114 | this.afterPrompt() |
| 115 | resolve(answer) |
| 116 | }) |
| 117 | |
| 118 | rl.on("close", () => { |
| 119 | this.isPrompting = false |
| 120 | this.afterPrompt() |
| 121 | }) |
| 122 | |
| 123 | rl.on("error", (err) => { |
| 124 | rl.close() |
| 125 | this.isPrompting = false |
| 126 | this.afterPrompt() |
| 127 | reject(err) |
| 128 | }) |
| 129 | }) |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Prompt for yes/no input. |
no test coverage detected