Prints a prompt and resolves on the next keypress. No-op when stdin isn't a TTY.
(prompt: string)
| 70 | |
| 71 | /** Prints a prompt and resolves on the next keypress. No-op when stdin isn't a TTY. */ |
| 72 | function waitForEnter(prompt: string): Promise<void> { |
| 73 | if (!process.stdin.isTTY) return Promise.resolve(); |
| 74 | return new Promise<void>((resolve) => { |
| 75 | process.stdout.write(` ${pc.dim(prompt)} `); |
| 76 | const onData = (chunk: Buffer) => { |
| 77 | // Ctrl-C |
| 78 | if (chunk[0] === 0x03) { |
| 79 | process.stdin.removeListener("data", onData); |
| 80 | process.stdin.setRawMode?.(false); |
| 81 | process.stdin.pause(); |
| 82 | process.stdout.write("\n"); |
| 83 | process.exit(130); |
| 84 | } |
| 85 | process.stdin.removeListener("data", onData); |
| 86 | process.stdin.setRawMode?.(false); |
| 87 | process.stdin.pause(); |
| 88 | process.stdout.write("\n"); |
| 89 | resolve(); |
| 90 | }; |
| 91 | process.stdin.setRawMode?.(true); |
| 92 | process.stdin.resume(); |
| 93 | process.stdin.on("data", onData); |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | async function announceIdentity(accessToken: string): Promise<string> { |
| 98 | try { |