Open
Description
PHP_CodeSniffer supports colourised output when requested. This can be enabled with --colors
and disabled with --no-colors
. By default, no colour is used in output.
Other tools can selectively show colours depending on the output destination.
For example, grep
in Linux has a single --color
(and equivalent --colour
) flag which takes an optional argument. The argument has three possible values: always
, never
, and auto
. (When the argument is not supplied, auto
is assumed.)
Describe the solution you'd like
PHP_CodeSniffer should have an auto-detection mode for colour support.
- [next minor] Create functionality within PHP_CodeSniffer to allow for auto-detecting if colour support could be enabled in the current output.
- Note that this functionality can be based on what has been done in other projects, like Symfony.
- [next minor] Adjust the existing
--colors
command-line flag to support an optional argument.
These suggestions are in line with other PHP command-line tools.--colors
behaves the same as--colors=always
--colors=always
turns on colour support--colors=auto
allows PHP_CodeSniffer to selectively enable / disable colourised output at its discretion.--colors=never
turns off colours support--no-colors
behaves the same as--colors=never
- [next minor] Soft-deprecate
--no-colors
flag. - [last minor] Hard-deprecate
--no-colors
flag. - [next minor +1, or next major] Change default value from
never
toauto
. - [next major] Remove
--no-colors
command-line flag
Future enhancements
- Review code-base for existing use of colourised output: check that these use proper colour codes, and respect the setting.
- Check for places where colours could be used, but are not currently.
- Consider helper methods / utility for adding colour to text.
- Consider if we should be adding colour always, and have an output processor remove colours as needed, or if we want to put
if
statements in the code where messages are generated. The helper methods / utility may be useful here.
Related issues / pull requests
- Use ANSI color codes and Unicode characters on Windows as well #662 ANSI color support on Windows
- I have read the Contribution Guidelines and this is not a support question.
- I intend to create a pull request to implement this feature.