xonecas.io
64875
Mc

mini-coder / commit c96779e

fix(cli): skip terminal restore escapes outside TTY

xonecas2026-03-14 c96779e6ada05ab167e58fe2378fa25f5b6b1c76 parent ac23235

2 files changed

src/cli/terminal-io.test.ts+37−0
@@ -0,0 +1,37 @@
1+import { afterEach, describe, expect, test } from "bun:test";
2+import { terminal } from "./terminal-io.ts";
3+
4+const originalWrite = terminal.stderrWrite.bind(terminal);
5+const originalIsTTY = process.stderr.isTTY;
6+
7+afterEach(() => {
8+ terminal.stderrWrite = originalWrite;
9+ process.stderr.isTTY = originalIsTTY;
10+});
11+
12+describe("terminal.restoreTerminal", () => {
13+ test("does not write cursor control escapes when stderr is not a TTY", () => {
14+ let output = "";
15+ terminal.stderrWrite = (text: string) => {
16+ output += text;
17+ };
18+ process.stderr.isTTY = false;
19+
20+ terminal.restoreTerminal();
21+
22+ expect(output).toBe("");
23+ });
24+
25+ test("writes cursor restore escapes when stderr is a TTY", () => {
26+ let output = "";
27+ terminal.stderrWrite = (text: string) => {
28+ output += text;
29+ };
30+ process.stderr.isTTY = true;
31+
32+ terminal.restoreTerminal();
33+
34+ expect(output).toContain("\x1B[?25h");
35+ expect(output).toContain("\r\x1B[2K");
36+ });
37+});
src/cli/terminal-io.ts+4−2
@@ -39,8 +39,10 @@ class TerminalIO {
3939
4040 restoreTerminal(): void {
4141 try {
42- this.stderrWrite("\x1B[?25h");
43- this.stderrWrite("\r\x1B[2K");
42+ if (this.isStderrTTY) {
43+ this.stderrWrite("\x1B[?25h");
44+ this.stderrWrite("\r\x1B[2K");
45+ }
4446 } catch {
4547 /* ignore */
4648 }