()
| 124 | let dataHandler: ((data: Buffer) => void) | null = null |
| 125 | |
| 126 | const cleanup = () => { |
| 127 | if (resolved) return |
| 128 | resolved = true |
| 129 | |
| 130 | if (timeoutId) { |
| 131 | clearTimeout(timeoutId) |
| 132 | timeoutId = null |
| 133 | } |
| 134 | |
| 135 | // Remove data handler from stdin |
| 136 | if (dataHandler) { |
| 137 | process.stdin.removeListener('data', dataHandler) |
| 138 | dataHandler = null |
| 139 | } |
| 140 | |
| 141 | // Restore raw mode state |
| 142 | if (process.stdin.isTTY && process.stdin.setRawMode) { |
| 143 | try { |
| 144 | process.stdin.setRawMode(wasRawMode) |
| 145 | } catch { |
| 146 | // Ignore errors restoring raw mode |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Pause stdin so we leave it non-flowing before other listeners attach |
| 151 | try { |
| 152 | process.stdin.pause() |
| 153 | } catch { |
| 154 | // Ignore pause errors |
| 155 | } |
| 156 | |
| 157 | // Close TTY write fd |
| 158 | if (ttyWriteFd !== null) { |
| 159 | try { |
| 160 | closeSync(ttyWriteFd) |
| 161 | } catch { |
| 162 | // Ignore close errors |
| 163 | } |
| 164 | ttyWriteFd = null |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | const resolveWith = (value: string | null) => { |
| 169 | if (resolved) return |
no test coverage detected