Skip to content

Commit 1b5d31c

Browse files
committed
fix: reopen /dev/tty before p.intro() so clack captures live TTY stream
1 parent bc23548 commit 1b5d31c

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/commands/create.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ export async function createAction(options: CreateOptions): Promise<void> {
4141
process.exit(1);
4242
}
4343

44-
// ── Read stdin ────────────────────────────────────────────────────────────
45-
p.intro(pc.bold("github-issue-ops") + pc.dim(" · issue create"));
46-
44+
// ── Read stdin (before any clack call) ───────────────────────────────────
45+
// Consume the pipe first, then reopen /dev/tty, then call p.intro() so that
46+
// clack captures the live terminal stream — not the already-EOF pipe.
4747
const raw = await readStdin();
4848
if (!raw) {
49-
p.cancel("No input detected. Pipe github-code-search output or JSON results into stdin.");
49+
process.stderr.write(
50+
`${pc.red("✘")} No input detected. Pipe github-code-search output or JSON results into stdin.\n`,
51+
);
5052
process.exit(1);
5153
}
5254

55+
// ── Restore TTY before initialising clack ────────────────────────────────
56+
// After readStdin() the pipe is at EOF. Re-open /dev/tty so that every
57+
// clack prompt (text, confirm, select…) reads from the physical terminal.
58+
reopenStdinAsTty();
59+
60+
p.intro(pc.bold("github-issue-ops") + pc.dim(" · issue create"));
61+
5362
const s = p.spinner();
5463
s.start("Parsing results…");
5564
const results = parseResults(raw);
@@ -62,11 +71,6 @@ export async function createAction(options: CreateOptions): Promise<void> {
6271
process.exit(1);
6372
}
6473

65-
// ── Restore TTY for interactive prompts ───────────────────────────────────
66-
// stdin was consumed by readStdin() above; re-open /dev/tty so that clack
67-
// prompts (text, confirm, select…) can still read from the terminal.
68-
reopenStdinAsTty();
69-
7074
// ── Resolve title ─────────────────────────────────────────────────────────
7175
let title = options.title;
7276
if (!title && !options.nonInteractive) {

src/tui/tty.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export function reopenStdinAsTty(): void {
2525
try {
2626
const fd = openSync("/dev/tty", "r+");
2727
const tty = new ReadStream(fd);
28+
// Mark the stream as a TTY so that clack (and other prompt libs) know they
29+
// are running in an interactive context and enable raw-mode input.
30+
(tty as unknown as Record<string, unknown>).isTTY = true;
2831
// @ts-expect-error — intentionally replacing the global stdin stream
2932
process.stdin = tty;
3033
process.stdin.resume();

0 commit comments

Comments
 (0)