public static function supportsColor($output)
    {
        if (defined('PHP_WINDOWS_VERSION_BUILD')) {
            return (function_exists('sapi_windows_vt100_support')
                && sapi_windows_vt100_support($output))
                || false !== getenv('ANSICON')
                || 'ON' === getenv('ConEmuANSI')
                || 'xterm' === getenv('TERM');
        }

        if (function_exists('stream_isatty')) {
            return stream_isatty($output);
        } elseif (function_exists('posix_isatty')) {
            return posix_isatty($output);
        }

        $stat = fstat($output);
        // Check if formatted mode is S_IFCHR
        return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
    }
public static function supportsColor($output)
    {
        if (defined('PHP_WINDOWS_VERSION_BUILD')) {
            return (function_exists('sapi_windows_vt100_support')
                && sapi_windows_vt100_support($output))
                || false !== getenv('ANSICON')
                || 'ON' === getenv('ConEmuANSI')
                || 'xterm' === getenv('TERM');
        }

        if (function_exists('stream_isatty')) {
            return stream_isatty($output);
        } elseif (function_exists('posix_isatty')) {
            return posix_isatty($output);
        }

        $stat = fstat($output);
        // Check if formatted mode is S_IFCHR
        return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
    }
public static function supportsColor ( $ output ) { if ( defined ( 'PHP_WINDOWS_VERSION_BUILD' ) ) { return ( function_exists ( 'sapi_windows_vt100_support' ) && sapi_windows_vt100_support ( $ output ) ) || false !== getenv ( 'ANSICON' ) || 'ON' === getenv ( 'ConEmuANSI' ) || 'xterm' === getenv ( 'TERM' ) ; } if ( function_exists ( 'stream_isatty' ) ) { return stream_isatty ( $ output ) ; } elseif ( function_exists ( 'posix_isatty' ) ) { return posix_isatty ( $ output ) ; } $ stat = fstat ( $ output ) ; // Check if formatted mode is S_IFCHR return $ stat ? 0020000 === ( $ stat [ 'mode' ] & 0170000 ) : false ; }
Returns true if the output stream supports colors

This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo
terminals via named pipes, so we can only check the environment.

@param mixed $output A valid CLI output stream

@return bool
Returns true if the output stream supports colors