Support disabling colors (ANSI escape sequences)
fho opened this issue · 4 comments
We are running local-php-security-checker as CI job.
The output of the tool is shown in the CI system and recorded in a file that is displayed to the user.
In both cases, the ANSI escape characters can not be interpreted and the raw escape codes are shown.
This makes the output a bit unreadable.
It would be great if it would be possible to disable the usage of ANSI escape sequences in the output.
A solution could be:
- support a
-format
command-line valueauto
.auto
would use ANSI escape sequences if an interactive terminal is used and the environment variableNO_COLOR
1 is not set. Otherwise the output would use ANSI escape sequences. Optionally also aplain
could be added that would always print non-ansi output.
To keep the CLI backwards compatible, theansi
option could be kept and use the current format. If you are willing to make a breaking change and want to keep it more simple, we could makeauto
the default, remove theansi
option and not have aplain
option.
An easy way to realize it could be to use the https://github.com/fatih/color package for coloring.
It supports already using colors only on interactive terminals and NO_COLOR
.
It also has support for windows, this might also fix the issue #53.
Let me know if I should provide a Pull-Request to make that change and if you would prefer using https://github.com/fatih/color or reimplementing the logic to disable colors.
Footnotes
If someone does the work and submit a PR, I will happily review it and merge it.