fabpot/local-php-security-checker

Support disabling colors (ANSI escape sequences)

fho opened this issue · 4 comments

fho commented

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 value auto. auto would use ANSI escape sequences if an interactive terminal is used and the environment variable NO_COLOR1 is not set. Otherwise the output would use ANSI escape sequences. Optionally also a plain could be added that would always print non-ansi output.
    To keep the CLI backwards compatible, the ansi 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 make auto the default, remove the ansi option and not have a plain 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

  1. https://no-color.org/

@fho repo looks largely abandoned, you can close this :)

If someone does the work and submit a PR, I will happily review it and merge it.

See #81