@@ -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+});