Skip to content

fix(cli): suppress ANSI escape codes in non-TTY progress output#124

Closed
miguel-heygen wants to merge 1 commit into03-29-fix_cli_include_all_9_templates_in_build_outputfrom
03-29-fix_cli_suppress_ansi_escape_codes_in_non-tty_progress_output
Closed

fix(cli): suppress ANSI escape codes in non-TTY progress output#124
miguel-heygen wants to merge 1 commit into03-29-fix_cli_include_all_9_templates_in_build_outputfrom
03-29-fix_cli_suppress_ansi_escape_codes_in_non-tty_progress_output

Conversation

@miguel-heygen
Copy link
Copy Markdown
Collaborator

@miguel-heygen miguel-heygen commented Mar 29, 2026

PR Stack

# PR Status
1 #122 — fix: info width/height swap ← base
2 #123 — fix: include all 9 templates in build
3 #124 — fix: suppress ANSI in non-TTY
4 #125 — fix: lint --json error paths
5 #126 — fix: separate info/warning counts
6 #127 — fix: lint severity display
7 #128 — fix: render output path error
8 #129 — fix: zero-duration error message ← top

Summary

  • renderProgress() was writing \r\x1b[2K escape codes even when stdout is not a TTY, corrupting output for CI pipelines and AI agents
  • Now checks stdout.isTTY and writes clean text lines at 10% intervals when piped/redirected

Reproducer

cd my-video
npx hyperframes render --output out.mp4 2>&1 | cat
# Output contained raw escape codes visible as garbled text
# Now outputs clean: "  50%  Capturing frames"

Stack

3/8 — Depends on #123

🤖 Generated with Claude Code

Copy link
Copy Markdown
Collaborator Author

@miguel-heygen miguel-heygen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate output lines at 10% boundaries

There's no dedup guard — multiple calls rounding to the same threshold will print duplicate lines. For example, if the producer calls with 49.7 then 50.1, both round to 50 and both satisfy rounded % 10 === 0:

  50%  encoding
  50%  encoding

Fix with a module-level guard:

let lastPrintedThreshold = -1;

// inside the non-TTY branch:
const rounded = Math.round(percent);
if ((rounded % 10 === 0 || rounded === 100) && rounded !== lastPrintedThreshold) {
  lastPrintedThreshold = rounded;
  stdout.write(`  ${rounded}%  ${stage}\n`);
}

Also worth considering: early-return for the non-TTY path to avoid computing the full bar/color line variable that's never used in that branch.

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
@miguel-heygen miguel-heygen force-pushed the 03-29-fix_cli_include_all_9_templates_in_build_output branch from 418aaf7 to c61ae83 Compare March 29, 2026 11:51
@miguel-heygen miguel-heygen force-pushed the 03-29-fix_cli_suppress_ansi_escape_codes_in_non-tty_progress_output branch from 78fd863 to 0b2576b Compare March 29, 2026 11:51
Copy link
Copy Markdown
Collaborator Author

@miguel-heygen miguel-heygen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed: added lastPrintedThreshold dedup guard to prevent duplicate lines. Also moved non-TTY check to early-return at top to skip unused bar/color computation.

@miguel-heygen
Copy link
Copy Markdown
Collaborator Author

Consolidated into fix/cli-polish.

@miguel-heygen miguel-heygen deleted the 03-29-fix_cli_suppress_ansi_escape_codes_in_non-tty_progress_output branch April 6, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant