123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace Symfony\Component\Console\Output;
- use Symfony\Component\Console\Exception\InvalidArgumentException;
- use Symfony\Component\Console\Formatter\OutputFormatterInterface;
- class StreamOutput extends Output
- {
- private $stream;
-
- public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null)
- {
- if (!\is_resource($stream) || 'stream' !== get_resource_type($stream)) {
- throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
- }
- $this->stream = $stream;
- if (null === $decorated) {
- $decorated = $this->hasColorSupport();
- }
- parent::__construct($verbosity, $decorated, $formatter);
- }
-
- public function getStream()
- {
- return $this->stream;
- }
- protected function doWrite(string $message, bool $newline)
- {
- if ($newline) {
- $message .= \PHP_EOL;
- }
- @fwrite($this->stream, $message);
- fflush($this->stream);
- }
-
- protected function hasColorSupport()
- {
-
- if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) {
- return false;
- }
- if (\DIRECTORY_SEPARATOR === '\\'
- && \function_exists('sapi_windows_vt100_support')
- && @sapi_windows_vt100_support($this->stream)
- ) {
- return true;
- }
- return 'Hyper' === getenv('TERM_PROGRAM')
- || false !== getenv('ANSICON')
- || 'ON' === getenv('ConEmuANSI')
- || str_starts_with((string) getenv('TERM'), 'xterm')
- || stream_isatty($this->stream);
- }
- }
|