Skip to content

[Console] Fix check of color support on Windows #26609

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

Merged
merged 1 commit into from
Apr 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,26 @@ protected function doWrite($message, $newline)
*
* Colorization is disabled if not supported by the stream:
*
* - Windows != 10.0.10586 without Ansicon, ConEmu or Mintty
* - the stream is redirected (eg php file.php >log)
* - Windows without VT100 support, Ansicon, ConEmu, Mintty
* - non tty consoles
*
* @return bool true if the stream supports colorization, false otherwise
*/
protected function hasColorSupport()
{
if (function_exists('stream_isatty') && !@stream_isatty($this->stream)) {
return false;
}
if (DIRECTORY_SEPARATOR === '\\') {
if (function_exists('sapi_windows_vt100_support')) {
$vt100Enabled = @sapi_windows_vt100_support($this->stream);
} else {
$vt100Enabled = '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD;
}

return
function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support($this->stream)
|| '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD
$vt100Enabled
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM');
Expand Down