Skip to content

Write HTML. Render video. Built for agents.

fix(cli): stream non-TTY render progress (#2458)

Miguel Ángelcada0e7c0933
diff --git a/packages/cli/src/ui/progress.test.ts b/packages/cli/src/ui/progress.test.ts
new file mode 100644
index 0000000000..8500779bf0
--- /dev/null
+++ b/packages/cli/src/ui/progress.test.ts
@@ -0,0 +1,33 @@
+import { afterEach, describe, expect, it } from "vitest";
+
+import { renderProgress } from "./progress.js";
+
+const originalWrite = process.stdout.write.bind(process.stdout);
+const originalIsTTY = process.stdout.isTTY;
+
+afterEach(() => {
+ process.stdout.write = originalWrite;
+ Object.defineProperty(process.stdout, "isTTY", {
+ value: originalIsTTY,
+ configurable: true,
+ });
+});
+
+describe("renderProgress", () => {
+ it("emits line-delimited updates when stdout is not a TTY", () => {
+ let output = "";
+ Object.defineProperty(process.stdout, "isTTY", {
+ value: false,
+ configurable: true,
+ });
+ process.stdout.write = ((chunk: string | Uint8Array) => {
+ output += String(chunk);
+ return true;
+ }) as typeof process.stdout.write;
+
+ renderProgress(42, "Capturing frames");
+
+ expect(output).toMatch(/Capturing frames\n$/);
+ expect(output).not.toContain("\r");
+ });
+});
diff --git a/packages/cli/src/ui/progress.ts b/packages/cli/src/ui/progress.ts
index f4aa4c3e4f..a109dfe6d8 100644
--- a/packages/cli/src/ui/progress.ts
+++ b/packages/cli/src/ui/progress.ts
@@ -12,6 +12,8 @@ export function renderProgress(percent: number, stage: string, row?: number): vo
if (row !== undefined && stdout.isTTY) {
stdout.write(`\x1b[${row};1H\x1b[2K${line}`);
+ } else if (!stdout.isTTY) {
+ stdout.write(`${line}\n`);
} else {
stdout.write(`\r\x1b[2K${line}`);
}