diff --git a/.changeset/lemon-monkeys-help.md b/.changeset/lemon-monkeys-help.md new file mode 100644 index 00000000..007c2d0c --- /dev/null +++ b/.changeset/lemon-monkeys-help.md @@ -0,0 +1,5 @@ +--- +"@clack/core": patch +--- + +Fix "TTY initialization failed: uv_tty_init returned EBADF (bad file descriptor)" error happening on Windows for non-tty terminals. diff --git a/packages/core/src/prompts/prompt.ts b/packages/core/src/prompts/prompt.ts index 6707450d..00dc143e 100644 --- a/packages/core/src/prompts/prompt.ts +++ b/packages/core/src/prompts/prompt.ts @@ -1,7 +1,7 @@ import { stdin, stdout } from 'node:process'; import readline, { type Key, type ReadLine } from 'node:readline'; -import type { Readable, Writable } from 'node:stream'; -import { WriteStream } from 'node:tty'; +import type { Readable } from 'node:stream'; +import { Writable } from 'node:stream'; import { cursor, erase } from 'sisteransi'; import wrap from 'wrap-ansi'; @@ -133,7 +133,7 @@ export default class Prompt { ); } - const sink = new WriteStream(0); + const sink = new Writable(); sink._write = (chunk, encoding, done) => { if (this._track) { this.value = this.rl?.line.replace(/\t/g, ''); @@ -150,6 +150,7 @@ export default class Prompt { tabSize: 2, prompt: '', escapeCodeTimeout: 50, + terminal: true, }); readline.emitKeypressEvents(this.input, this.rl); this.rl.prompt();