mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-01 19:42:03 +00:00
fix(cli): suppress ANSI escape codes in non-TTY progress output
renderProgress() was writing \r\x1b[2K escape codes even when stdout is not a TTY, corrupting output for CI pipelines and AI agents. Now writes clean text lines at 10% intervals when not a TTY. Reproducer: cd my-video npx hyperframes render --output out.mp4 2>&1 | cat # Output contained raw escape codes: \x1b[2K
This commit is contained in:
@@ -2,7 +2,19 @@ import { c } from "./colors.js";
|
||||
|
||||
const { stdout } = process;
|
||||
|
||||
let lastPrintedThreshold = -1;
|
||||
|
||||
export function renderProgress(percent: number, stage: string, row?: number): void {
|
||||
// Non-TTY: write clean lines at 10% intervals, skip bar computation entirely
|
||||
if (!stdout.isTTY) {
|
||||
const rounded = Math.round(percent);
|
||||
if ((rounded % 10 === 0 || rounded === 100) && rounded !== lastPrintedThreshold) {
|
||||
lastPrintedThreshold = rounded;
|
||||
stdout.write(` ${rounded}% ${stage}\n`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const width = 25;
|
||||
const filled = Math.floor(percent / (100 / width));
|
||||
const empty = width - filled;
|
||||
@@ -10,7 +22,7 @@ export function renderProgress(percent: number, stage: string, row?: number): vo
|
||||
|
||||
const line = ` ${bar} ${c.bold(String(Math.round(percent)) + "%")} ${c.dim(stage)}`;
|
||||
|
||||
if (row !== undefined && stdout.isTTY) {
|
||||
if (row !== undefined) {
|
||||
stdout.write(`\x1b[${row};1H\x1b[2K${line}`);
|
||||
} else {
|
||||
stdout.write(`\r\x1b[2K${line}`);
|
||||
|
||||
Reference in New Issue
Block a user