-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ANSI color codes and Unicode characters on Windows as well #662
base: master
Are you sure you want to change the base?
Conversation
@MatmaRex Thanks for the PR. However, similar to the other PR, I need to ask you to please either provide a reproduction scenario, screenshots or tests to demonstrate what you are trying to solve. Preferably all three of these should be provided with any PR which changes things in the UI. I can take a guess what you are trying to solve, but my guess may be wrong, so without any of the above, I can't even begin to properly evaluate the PR.
PHPCS 3.x still has a minimum supported PHP version of PHP 5.4, so we cannot rely on features from PHP 7.2. I could tentatively earmark this PR for PHPCS 4.0 , which will have a PHP 7.2 minimum, but that still doesn't negate my remarks above. |
While using Windows 10 or newer, and PHP 7.2 or newer, run PHPCS with
Note:
The If you really want to support these old systems, the only thing to do would be to disable |
Oh, right, the "visible" characters are still applied in The encoding issue is interesting – it happens with PHP 7.0, but not with PHP 7.1, which I tested with.
I'm not very familiar with GitHub's CI – can you point out which of the jobs run on Windows? |
Might just be that PHP added support for the Windows ANSI codes in PHP 7.1 and only added the function related to it in PHP 7.2.
At this time, there are no runs on Windows as there are no tests covering code which has special conditions for Windows. As soon as such tests would be added, the Windows OS would have to be added to the test matrix/workflow. (No worries about that, I can do that). |
2ec254b
to
e64ea14
Compare
The ANSI codes and the Unicode characters actually appear unrelated. I found a PHP doc page that documents the latter as a change in PHP 7.1. https://www.php.net/manual/en/migration71.windows-support.php
I guess I can try adding some. Probably in yet another pull request. |
e64ea14
to
294252d
Compare
This reduces the size of the output, and lessens weird effects of the ANSI color code characters on text wrapping, when the result of this method is used in a sniff error message (e.g. see LanguageConstructSpacingSniff).
Windows' console supports ANSI escape sequences since Windows 10. https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences PHP enables this by default since PHP 7.2. https://www.php.net/manual/en/function.sapi-windows-vt100-support.php On older PHP versions, the output with --colors will not be correct, but this is already the case when using this option. PHP CodeSniffer special-cased Windows in this code in 2014 (bfd095d). This workaround is no longer needed today in 2024. Note that the --colors option was already supported on Windows. This only affects inline highlighting in error and debug messages.
294252d
to
9a33b8c
Compare
I extended the changes here slightly, adding two additional commits (see commit messages for details):
|
9a33b8c
to
ff05ec9
Compare
…PHP 7.1+ PHP 7.1 fixed problems with printing Unicode characters to Windows console that forced us to avoid using them. https://www.php.net/manual/en/migration71.windows-support.php
ff05ec9
to
8e976bc
Compare
Sorry about the noise, I didn't realize at first that PHPUnit 4.8 (used on PHP 5.4) does not support the |
@jrfnl I greatly appreciate your reviews so far. I'd love to hear your thoughts on these patches again whenever you have the time. Please do not feel hurried though, I just want to make it clear that I'm still interested in completing these changes! |
Description
Use ANSI color codes and Unicode characters on Windows as well, when possible. See commit messages for details.
Suggested changelog entry
--colors
option, the output now has more colors.Related issues/external references
(none)
Types of changes
PR checklist