Returns true if the stream supports colorization.

Reference: Composer\XdebugHandler\Process::supportsColor
https://github.com/composer/xdebug-handler

@param mixed $stream A CLI output stream

@return bool
767560
private function hasColorSupport($stream)
    {
        if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) {
            return false;
        }

        if ('Hyper' === getenv('TERM_PROGRAM')) {
            return true;
        }

        if (\DIRECTORY_SEPARATOR === '\\') {
            return (\function_exists('sapi_windows_vt100_support')
                && @sapi_windows_vt100_support($stream))
                || false !== getenv('ANSICON')
                || 'ON' === getenv('ConEmuANSI')
                || 'xterm' === getenv('TERM');
        }

        if (\function_exists('stream_isatty')) {
            return @stream_isatty($stream);
        }

        if (\function_exists('posix_isatty')) {
            return @posix_isatty($stream);
        }

        $stat = @fstat($stream);
        // Check if formatted mode is S_IFCHR
        return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
    }
503995
public function isWritable()
    {
        if (!$this->isValidResource($this->resource)) {
            return false;
        }

        $meta = stream_get_meta_data($this->resource);
        $mode = $meta['mode'];

        return (
            strstr($mode, 'x')
            || strstr($mode, 'w')
            || strstr($mode, 'c')
            || strstr($mode, 'a')
            || strstr($mode, '+')
        );
    }
1355937
public function readBinaryStream($stream)
    {
        if (($str = stream_get_contents($stream)) === false || empty($str)) {
            throw new PListException("Error reading stream!");
        }

        $this->parseBinary($str);
    }
15983
public function stream_write($data)
    {
        if ( ! $this->stream instanceof WritableStream) {
            return 0;
        }

        try {
            return $this->stream->writeBytes($data);
        } catch (Exception $e) {
            trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), \E_USER_WARNING);
            return false;
        }
    }
178831
protected function extractTableName($stream)
    {
        if ($stream->getNextExpected(T_WHITESPACE) === null) {
            return false;
        }

        if ($stream->getNextExpected(T_VARIABLE) === null) {
            return false;
        }

        if ($stream->getCurrentText() != '$table') {
            return false;
        }

        if ($stream->getNextExpectedTerminated(['=', T_WHITESPACE], [T_CONSTANT_ENCAPSED_STRING]) === null) {
            return null;
        }

        $tableName = $stream->getCurrentText();
        $tableName = trim($tableName, '\''); 
        $tableName = trim($tableName, '"'); 

        return $tableName;
    }
251262
private function supports(string $class): bool
    {
        $class = new \ReflectionClass($class);

        // We look for at least one non-static property
        do {
            foreach ($class->getProperties() as $property) {
                if (!$property->isStatic()) {
                    return true;
                }
            }
        } while ($class = $class->getParentClass());

        return false;
    }
642461
public static function isSupportedEvent(string $event): bool
    {
        if (!$event || !preg_match('/[a-zA-z][\w-]+/', $event)) {
            return false;
        }

        if ($ets = self::$supportedEvents) {
            return \in_array($event, $ets, true);
        }

        return true;
    }
1252768
public function stream_cast($castAs)
    {
        if ($this->fileHandle !== null && $castAs & STREAM_CAST_AS_STREAM) {
            return $this->fileHandle;
        } else {
            return false;
        }
    }
1202963
private function isStreamWritable($path)
    {
        $stream = $this->getStreamByPathScheme($path);
        if ($stream instanceof StreamInterface) {
            return $stream->isWritable();
        }

        return false;
    }
1224887
public function endRecording($stream)
    {
        $parts = explode('/', $this->streamserver_config[$stream->getRtmpServer()]['rtmp_url']);
        $rtmp_app = end($parts);
        $success = $this->record(
            $this->streamserver_config[$stream->getRtmpServer()]['rtmp_control'],
            $rtmp_app,
            $stream->getUniqID(),
            false
        );
        if ($success) {
            $stream->setTechnicalStatus(Stream::STATE_ENDED);
            $this->em->persist($stream);
            $this->em->flush();

            // $event = new EndRecordingStreamEvent($stream);
            // $this->dispatcher->dispatch(
            //     OktolabMediaEvent::STREAM_END_RECORDING,
            //     $event
            // );
            return true;
        }
        return false;
    }
970600
public function write($data = null) {
		if (!is_resource($this->_resource)) {
			return false;
		}
		if (!is_object($data)) {
			$data = $this->_instance($this->_classes['request'], (array) $data + $this->_config);
		}
		return stream_context_set_option(
			$this->_resource, $data->to('context', ['timeout' => $this->_timeout])
		);
	}
1025110
static public function shouldColorize($colored = null) {
		return self::$_enabled === true ||
			(self::$_enabled !== false &&
				($colored === true ||
					($colored !== false && Streams::isTty())));
	}
1288270
public function storeColorScheme($colors) : bool
    {
        if (!is_array($colors) && !is_object($colors)) {
            $colors = array();
        }

        return update_option($this->optionName, (array) $this->sanitizeColorSheme($colors), false);
    }
280439
private function parseExport(Stream $stream)
    {
        $stream->expects(Token::TYPE_KEYWORD, 'export');

        if ($stream->current()->equals(Token::TYPE_KEYWORD, 'type')) {
            $stream->expects(Token::TYPE_KEYWORD, 'type');

            $typeName = $this->parseIdentifier($stream);
            $alias = null;

            if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
                $stream->expects(Token::TYPE_KEYWORD, 'as');

                $alias = $this->parseIdentifier($stream);
            }

            $stream->expects(Token::TYPE_SYMBOL, ';');

            return new MapperExportNode($typeName, $alias);
        }

        if ($stream->current()->equals(Token::TYPE_KEYWORD, 'function')) {
            $stream->expects(Token::TYPE_KEYWORD, 'function');

            $functionName = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
            $alias = null;

            if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
                $stream->expects(Token::TYPE_KEYWORD, 'as');

                $alias = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
            }

            $stream->expects(Token::TYPE_SYMBOL, ';');

            return new BlueprintExportNode($functionName, $alias);
        }

        if ($stream->current()->equals(Token::TYPE_KEYWORD, 'template')) {
            $stream->expects(Token::TYPE_KEYWORD, 'template');

            $templateName = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
            $alias = null;

            if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
                $stream->expects(Token::TYPE_KEYWORD, 'as');

                $alias = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
            }

            $stream->expects(Token::TYPE_SYMBOL, ';');

            return new BlueprintExportNode($templateName, $alias);
        }

        throw new ParserException(sprintf(
            'Can\'t parse the stream "%s". Expects the keyword "type", "function" or "template".',
            $stream->humanize()
        ));
    }
543570
protected function hasColorSupport()
    {
        // @codeCoverageIgnoreStart
        if (DIRECTORY_SEPARATOR == '\\') {
            return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
        }

        return function_exists('posix_isatty') && @posix_isatty($this->stream->stream);
        // @codeCoverageIgnoreEnd
    }
1093684
public function readSFixed64(Stream $stream)
    {
        $bytes = $stream->read(8);

        list(, $lo0, $lo1, $hi0, $hi1) = unpack('v*', $bytes);

        return ($hi1 << 16 | $hi0) << 32 | ($lo1 << 16 | $lo0);
    }
796068
def is_color_supported():
    ""
    # shinx.util.console
    if not hasattr(sys.stdout, 'isatty'):
        return False

    if not sys.stdout.isatty() and 'TERMINAL-COLOR' not in os.environ:
        return False

    if sys.platform == 'win32':  # pragma: no cover
        try:
            import colorama
            colorama.init()
            return True
        except ImportError:
            return False

    if 'COLORTERM' in os.environ:
        return True

    term = os.environ.get('TERM', 'dumb').lower()
    return term in ('xterm', 'linux') or 'color' in term