Skip to content

[ax] Never emit ANSI when output is not a TTY, even with --ansi - #8453

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-force-no-ansi-non-tty
Sep 4, 2026
Merged

[ax] Never emit ANSI when output is not a TTY, even with --ansi#8453
TomasVotruba merged 2 commits into
mainfrom
tv-force-no-ansi-non-tty

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Why

When output is piped, redirected or captured by an agent, colored output is noise - ANSI escape bytes an agent has to strip. Symfony already drops color on a non-TTY by default, but an explicit --ansi overrides that detection and forces color even into a pipe:

rector process --dry-run --ansi | tee out.txt   # out.txt held raw escape codes

What

Force console decoration off when STDOUT is not a TTY, regardless of --ansi. Real terminals are unaffected (they keep color); only non-interactive output is guaranteed clean.

// SymfonyStyleFactory::create()
if (! (defined('STDOUT') && stream_isatty(STDOUT))) {
    $consoleOutput->setDecorated(false);
}

Same non-TTY detection used for the progress bar in #8444.

Verification

Piping a run with --ansi (2 changed lines):

  • before: 12 ANSI escape sequences in the captured output
  • after: 0

Plain piped output was already clean (0) and stays 0; interactive terminal output keeps color.

This is env-dependent output plumbing that reads the real STDOUT stream, so it is verified via the CLI before/after rather than a unit test.

@TomasVotruba TomasVotruba changed the title [Console] Never emit ANSI when output is not a TTY, even with --ansi [ax] Never emit ANSI when output is not a TTY, even with --ansi Sep 4, 2026
@TomasVotruba
TomasVotruba merged commit 377b2e6 into main Sep 4, 2026
43 checks passed
@TomasVotruba
TomasVotruba deleted the tv-force-no-ansi-non-tty branch September 4, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants