Skip to content

Commit 28ebe60

Browse files
Merge branch '2.7' into 2.8
* 2.7: [VarDumper] Remove decoration from actual output in tests [Bridge/Doctrine] fix count() notice on PHP 7.2 [Security] Skip user checks if not implementing UserInterface [HttpFoundation] Add HTTP_EARLY_HINTS const [DoctrineBridge] Improve exception message at `IdReader::getIdValue()` fixed CS Use new PHP7.2 functions in hasColorSupport [VarDumper] Fix dumping of SplObjectStorage
2 parents a3c6603 + 2787460 commit 28ebe60

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Output/StreamOutput.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,34 @@ protected function doWrite($message, $newline)
8383
*
8484
* Colorization is disabled if not supported by the stream:
8585
*
86-
* - the stream is redirected (eg php file.php >log)
87-
* - Windows without VT100 support, Ansicon, ConEmu, Mintty
88-
* - non tty consoles
86+
* This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo
87+
* terminals via named pipes, so we can only check the environment.
88+
*
89+
* Reference: Composer\XdebugHandler\Process::supportsColor
90+
* https://github.com/composer/xdebug-handler
8991
*
9092
* @return bool true if the stream supports colorization, false otherwise
9193
*/
9294
protected function hasColorSupport()
9395
{
94-
if (function_exists('stream_isatty') && !@stream_isatty($this->stream)) {
95-
return false;
96-
}
9796
if (DIRECTORY_SEPARATOR === '\\') {
98-
if (function_exists('sapi_windows_vt100_support')) {
99-
$vt100Enabled = @sapi_windows_vt100_support($this->stream);
100-
} else {
101-
$vt100Enabled = '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD;
102-
}
103-
104-
return
105-
$vt100Enabled
97+
return (function_exists('sapi_windows_vt100_support')
98+
&& @sapi_windows_vt100_support($this->stream))
10699
|| false !== getenv('ANSICON')
107100
|| 'ON' === getenv('ConEmuANSI')
108101
|| 'xterm' === getenv('TERM');
109102
}
110103

111-
return function_exists('posix_isatty') && @posix_isatty($this->stream);
104+
if (function_exists('stream_isatty')) {
105+
return @stream_isatty($this->stream);
106+
}
107+
108+
if (function_exists('posix_isatty')) {
109+
return @posix_isatty($this->stream);
110+
}
111+
112+
$stat = @fstat($this->stream);
113+
// Check if formatted mode is S_IFCHR
114+
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
112115
}
113116
}

0 commit comments

Comments
 (0)