@@ -81,31 +81,34 @@ protected function doWrite($message, $newline)
81
81
*
82
82
* Colorization is disabled if not supported by the stream:
83
83
*
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
87
89
*
88
90
* @return bool true if the stream supports colorization, false otherwise
89
91
*/
90
92
protected function hasColorSupport ()
91
93
{
92
- if (function_exists ('stream_isatty ' ) && !@stream_isatty ($ this ->stream )) {
93
- return false ;
94
- }
95
94
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 ))
104
97
|| false !== getenv ('ANSICON ' )
105
98
|| 'ON ' === getenv ('ConEmuANSI ' )
106
99
|| 'xterm ' === getenv ('TERM ' );
107
100
}
108
101
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 ;
110
113
}
111
114
}
0 commit comments