mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix(cli): stream non-TTY render progress (#2458)
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user