Skip to content

Commit 2787460

Browse files
committed
bug #26910 Use new PHP7.2 functions in hasColorSupport (johnstevenson)
This PR was squashed before being merged into the 2.7 branch (closes #26910). Discussion ---------- Use new PHP7.2 functions in hasColorSupport | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Fixes bc break in #26609 Reference: https://github.com/composer/xdebug-handler/blob/master/src/Process.php#L111 Commits ------- b0c92254a0 Use new PHP7.2 functions in hasColorSupport
2 parents be24d90 + 6bef4f5 commit 2787460

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
@@ -81,31 +81,34 @@ protected function doWrite($message, $newline)
8181
*
8282
* Colorization is disabled if not supported by the stream:
8383
*
84-
* - the stream is redirected (eg php file.php >log)
85-
* - Windows without VT100 support, Ansicon, ConEmu, Mintty
86-
* - non tty consoles
84+
* This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo
85+
* terminals via named pipes, so we can only check the environment.
86+
*
87+
* Reference: Composer\XdebugHandler\Process::supportsColor
88+
* https://github.com/composer/xdebug-handler
8789
*
8890
* @return bool true if the stream supports colorization, false otherwise
8991
*/
9092
protected function hasColorSupport()
9193
{
92-
if (function_exists('stream_isatty') && !@stream_isatty($this->stream)) {
93-
return false;
94-
}
9594
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-
102-
return
103-
$vt100Enabled
95+
return (function_exists('sapi_windows_vt100_support')
96+
&& @sapi_windows_vt100_support($this->stream))
10497
|| false !== getenv('ANSICON')
10598
|| 'ON' === getenv('ConEmuANSI')
10699
|| 'xterm' === getenv('TERM');
107100
}
108101

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

0 commit comments

Comments
 (0)