Skip to content

Commit 5f5a717

Browse files
mlocatinicolas-grekas
authored andcommitted
Windows 10 version check in just one line
1 parent 01fb26b commit 5f5a717

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ public static function register($mode = false)
160160
private static function hasColorSupport()
161161
{
162162
if ('\\' === DIRECTORY_SEPARATOR) {
163-
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
163+
return
164+
0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD)
165+
|| false !== getenv('ANSICON')
166+
|| 'ON' === getenv('ConEmuANSI')
167+
|| 'xterm' === getenv('TERM');
164168
}
165169

166170
return defined('STDOUT') && function_exists('posix_isatty') && @posix_isatty(STDOUT);

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function __construct($output = null, $charset = null)
5858
{
5959
parent::__construct($output, $charset);
6060

61-
if ('\\' === DIRECTORY_SEPARATOR && false !== @getenv('ANSICON')) {
62-
// Use only the base 16 xterm colors when using ANSICON
61+
if ('\\' === DIRECTORY_SEPARATOR && 'ON' !== @getenv('ConEmuANSI') && 'xterm' !== @getenv('TERM')) {
62+
// Use only the base 16 xterm colors when using ANSICON or standard Windows 10 CLI
6363
$this->setStyles(array(
6464
'default' => '31',
6565
'num' => '1;34',
@@ -448,7 +448,12 @@ protected function supportsColors()
448448
}
449449

450450
if ('\\' === DIRECTORY_SEPARATOR) {
451-
static::$defaultColors = @(false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'));
451+
static::$defaultColors = @(
452+
0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD)
453+
|| false !== getenv('ANSICON')
454+
|| 'ON' === getenv('ConEmuANSI')
455+
|| 'xterm' === getenv('TERM')
456+
);
452457
} elseif (function_exists('posix_isatty')) {
453458
$h = stream_get_meta_data($this->outputStream) + array('wrapper_type' => null);
454459
$h = 'Output' === $h['stream_type'] && 'PHP' === $h['wrapper_type'] ? fopen('php://stdout', 'wb') : $this->outputStream;

0 commit comments

Comments
 (0)