-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Detect CLI color support for Windows 10 build 10586 #18385
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
Conversation
Newer Windows 10 versions (builds older than 10586) offer VT100 color support. See http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-(v1511)-Console-Host-Enhancements
note that the VarDumper component has similar logic that should be patched also |
@@ -93,7 +93,16 @@ protected function doWrite($message, $newline) | |||
protected function hasColorSupport() | |||
{ | |||
if (DIRECTORY_SEPARATOR === '\\') { | |||
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); | |||
return | |||
defined('PHP_WINDOWS_VERSION_MAJOR') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, PHP_WINDOWS_VERSION_MAJOR
goves the version of Windows where PHP was compiled, not the version where it runs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, PHP_WINDOWS_VERSION_MAJOR goves the version of Windows where PHP was compiled, not the version where it runs
@stof Whoops, you're right!
not a bugfix IMO (especially given that we can already force it with a CLI flag) |
No, it's not true. They are determined at runtime. I diggered a bit into these I tested exactly the same PHP executables under these different PCs:
And here's the values of the three constants (concatenated with dots for simplicity) for every PHP version and every PC:
For these versions:
the detected Windows version is wrong because of this Windows change. These versions:
have this patch, so those versions have a reliable value for the constants. Given all that, I think that this pull request is still valid, but it will work only for PHP 5.5 >= 5.5.27, PHP 5.6 >= 5.6.11 and PHP 7+ (older versions will continue to work as before). So, @stof, shall I reopen this PR? |
PS: a more reliable way to determine the exact Windows version would be to use
|
it is fine if the autodetection works fine only in uptodate PHP versions. Not detecting color support won't break the console (it will just fallback to non colored output by default) |
Newer Windows 10 versions (builds older than 10586) offer VT100 color support. See http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-(v1511)-Console-Host-Enhancements
I updated this PR, adding the Windows 10 detection code to |
@@ -194,7 +194,16 @@ public static function register($mode = 0) | |||
private static function hasColorSupport() | |||
{ | |||
if ('\\' === DIRECTORY_SEPARATOR) { | |||
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); | |||
return | |||
defined('PHP_WINDOWS_VERSION_MAJOR') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this part actually needed ? We already detect windows just before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just detected that the directory separator in \
... I'm not 100% sure it's only used in Windows (there are more OSs out there than just *nix, Windows and Mac... What about OS2? Others?....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can safely state that only Windows does '\\' === DIRECTORY_SEPARATOR
👍, as a bug fix on 2.3 to me... |
I don't think it qualifies as a bug fix (and this PR does not apply cleanly on 2.3 as two files did not exist back then). For such a PR, I propose to merge it on master and be done with it. |
Thank you @mlocati. |
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #18385). Discussion ---------- Detect CLI color support for Windows 10 build 10586 Newer Windows 10 versions (builds starting from 10586) offer VT100 color support. See http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-(v1511)-Console-Host-Enhancements | Q | A | ------------- | --- | Branch? | master - Maybe it could be backported to other branches too | Bug fix? | maybe 😉 - Do you you consider a bug not having colors on Windows? | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 472a7bf Detect CLI color support for Windows 10 build 10586
Newer Windows 10 versions (builds starting from 10586) offer VT100 color support.
See http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-(v1511)-Console-Host-Enhancements