Skip to content

Commit 505b038

Browse files
committed
Fix check of color support on Windows
If the stream is redirected, the script should behave the same on Windows and on POSIX systems.
1 parent 926047a commit 505b038

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Output/StreamOutput.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,26 @@ protected function doWrite($message, $newline)
8181
*
8282
* Colorization is disabled if not supported by the stream:
8383
*
84-
* - Windows != 10.0.10586 without Ansicon, ConEmu or Mintty
84+
* - the stream is redirected (eg php file.php >log)
85+
* - Windows without VT100 support, Ansicon, ConEmu, Mintty
8586
* - non tty consoles
8687
*
8788
* @return bool true if the stream supports colorization, false otherwise
8889
*/
8990
protected function hasColorSupport()
9091
{
92+
if (function_exists('stream_isatty') && !@stream_isatty($this->stream)) {
93+
return false;
94+
}
9195
if (DIRECTORY_SEPARATOR === '\\') {
96+
if (function_exists('sapi_windows_vt100_support')) {
97+
$vt100Enabled = @sapi_windows_vt100_support($this->stream);
98+
} else {
99+
$vt100Enabled = '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD;
100+
}
101+
92102
return
93-
function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support($this->stream)
94-
|| '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD
103+
$vt100Enabled
95104
|| false !== getenv('ANSICON')
96105
|| 'ON' === getenv('ConEmuANSI')
97106
|| 'xterm' === getenv('TERM');

0 commit comments

Comments
 (0)