@@ -4,6 +4,7 @@ import type { TurnEvent } from "../llm-api/types.ts";
44 import { Spinner } from "./spinner.ts";
55 import { renderTurn } from "./stream-render.ts";
66 import { terminal } from "./terminal-io.ts";
7+import { withTerminalColumns } from "./test-helpers.ts";
78
89 let stdout = "";
910 const originalStdoutWrite = terminal.stdoutWrite.bind(terminal);
@@ -106,32 +107,6 @@ function hasAnsi(s: string, code: string): boolean {
106107 return s.includes(`${String.fromCharCode(0x1b)}${code}`);
107108 }
108109
109-async function withTerminalColumns(
110- cols: number,
111- fn: () => Promise<void>,
112-): Promise<void> {
113- const out = process.stdout as NodeJS.WriteStream & { columns?: number };
114- const previous = Object.getOwnPropertyDescriptor(out, "columns");
115- Object.defineProperty(out, "columns", {
116- value: cols,
117- configurable: true,
118- writable: true,
119- });
120- try {
121- await fn();
122- } finally {
123- if (previous) {
124- Object.defineProperty(out, "columns", previous);
125- } else {
126- Object.defineProperty(out, "columns", {
127- value: undefined,
128- configurable: true,
129- writable: true,
130- });
131- }
132- }
133-}
134-
135110 function countOccurrences(haystack: string, needle: string): number {
136111 return haystack.split(needle).length - 1;
137112 }