Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61feb7d

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 a1be12e commit 61feb7d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Symfony/Component/Console/Output/StreamOutput.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,25 @@ 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+
}
92101
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
102+
$vt100Enabled
95103
|| false !== getenv('ANSICON')
96104
|| 'ON' === getenv('ConEmuANSI')
97105
|| 'xterm' === getenv('TERM');

0 commit comments

Comments
 (0)