Skip to content

No color codes in the CLI's own output when it is piped - #58

Merged
mnapoli merged 1 commit into
mainfrom
cli-piped-output-no-ansi
Sep 27, 2026
Merged

mnapoli merged 1 commit into
mainfrom
cli-piped-output-no-ansi

Conversation

@mnapoli

@mnapoli mnapoli commented Sep 27, 2026

Copy link
Copy Markdown
Member

When the output of bref is piped or redirected (bref command ... | cat, > file.log, CI), the CLI's own lines (the spinner/progress lines and the verbose logs it shows by default in non-interactive environments) still contained ANSI color codes.

The cause: Styles builds colors as raw escape codes ("\e[31m{$text}\e[39m"), not Symfony formatter tags, and Symfony only strips its own tags when the output is not decorated.

IO and the spinner now strip these codes when the output is not decorated, using Symfony's decoration detection (pipes, NO_COLOR, FORCE_COLOR). In a terminal, the output is byte-for-byte identical.

Since everything goes through IO, a piped bref command also drops the color codes contained in the command's own output. That's consistent with #57, which only asks Bref Cloud for colors when the output is a terminal.

Tested with new IOTest/StylesTest tests (spinner, verbose, warning, error, decorated and not), and by comparing the raw bytes of a piped run before/after (cat -v): no escape codes left when piped, identical output when decorated.

@mnapoli
mnapoli merged commit bd72274 into main Sep 27, 2026
4 checks passed
@mnapoli
mnapoli deleted the cli-piped-output-no-ansi branch September 27, 2026 21:44
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