diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index cf0de6c..46ab89e 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -400,29 +400,29 @@ private static function hasColorSupport(): bool return false; } - if ('Hyper' === getenv('TERM_PROGRAM')) { + // Detect msysgit/mingw and assume this is a tty because detection + // does not work correctly, see https://github.com/composer/composer/issues/9690 + if (!@stream_isatty($stream) && !\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) { return true; } - if (\DIRECTORY_SEPARATOR === '\\') { - return (\function_exists('sapi_windows_vt100_support') - && sapi_windows_vt100_support(\STDOUT)) - || false !== getenv('ANSICON') - || 'ON' === getenv('ConEmuANSI') - || 'xterm' === getenv('TERM'); + if ('\\' === \DIRECTORY_SEPARATOR && @sapi_windows_vt100_support(\STDOUT)) { + return true; } - if (\function_exists('stream_isatty')) { - return @stream_isatty(\STDOUT); + if ('Hyper' === getenv('TERM_PROGRAM') + || false !== getenv('COLORTERM') + || false !== getenv('ANSICON') + || 'ON' === getenv('ConEmuANSI') + ) { + return true; } - if (\function_exists('posix_isatty')) { - return @posix_isatty(\STDOUT); + if ('dumb' === $term = (string) getenv('TERM')) { + return false; } - $stat = fstat(\STDOUT); - - // Check if formatted mode is S_IFCHR - return $stat ? 0020000 === ($stat['mode'] & 0170000) : false; + // See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157 + return preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term); } }