bug #18385 Detect CLI color support for Windows 10 build 10586 (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
This commit is contained in:
Nicolas Grekas 2016-04-04 19:01:24 +02:00
commit 5fbfcb05d5
1 changed files with 6 additions and 2 deletions

View File

@ -85,7 +85,7 @@ class StreamOutput extends Output
*
* Colorization is disabled if not supported by the stream:
*
* - Windows without Ansicon, ConEmu or Mintty
* - Windows before 10.0.10586 without Ansicon, ConEmu or Mintty
* - non tty consoles
*
* @return bool true if the stream supports colorization, false otherwise
@ -94,7 +94,11 @@ class StreamOutput extends Output
{
// @codeCoverageIgnoreStart
if (DIRECTORY_SEPARATOR === '\\') {
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
return
0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD)
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM');
}
return function_exists('posix_isatty') && @posix_isatty($this->stream);