-
-
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
Changes from 1 commit
70db2c0
1ab5544
5530fac
6e676c4
a226d77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,15 +85,24 @@ protected function doWrite($message, $newline) | |
* | ||
* 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 | ||
*/ | ||
protected function hasColorSupport() | ||
{ | ||
if (DIRECTORY_SEPARATOR === '\\') { | ||
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); | ||
return | ||
defined('PHP_WINDOWS_VERSION_MAJOR') | ||
&& | ||
version_compare( | ||
PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD, | ||
'10.0.10586' | ||
) >= 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest using a one-liner here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|| false !== getenv('ANSICON') | ||
|| 'ON' === getenv('ConEmuANSI') | ||
|| 'xterm' === getenv('TERM'); | ||
} | ||
|
||
return function_exists('posix_isatty') && @posix_isatty($this->stream); | ||
|
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 runsThere 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.
@stof Whoops, you're right!