From 3a09f2ffad47d636359ef03d1de28320181509be Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 8 Feb 2024 08:18:31 +0100 Subject: [PATCH] [PhpUnitBridge][VarDumper] fix color detection --- .../PhpUnit/DeprecationErrorHandler.php | 7 ++----- .../Component/Console/Output/StreamOutput.php | 21 +++---------------- .../Component/VarDumper/Dumper/CliDumper.php | 2 +- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index e5396dd05edcc..adddfe6f76995 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -404,13 +404,10 @@ private static function hasColorSupport() } if (!self::isTty()) { - return true; + return false; } - if ('\\' === \DIRECTORY_SEPARATOR - && \function_exists('sapi_windows_vt100_support') - && @sapi_windows_vt100_support(\STDOUT) - ) { + if ('\\' === \DIRECTORY_SEPARATOR && \function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(\STDOUT)) { return true; } diff --git a/src/Symfony/Component/Console/Output/StreamOutput.php b/src/Symfony/Component/Console/Output/StreamOutput.php index 95dc00a44eed6..5f5ffce329b93 100644 --- a/src/Symfony/Component/Console/Output/StreamOutput.php +++ b/src/Symfony/Component/Console/Output/StreamOutput.php @@ -95,7 +95,9 @@ protected function hasColorSupport() return false; } - if (!$this->isTty()) { + // 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($this->stream) && !\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) { return false; } @@ -118,21 +120,4 @@ protected function hasColorSupport() // 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); } - - /** - * Checks if the stream is a TTY, i.e; whether the output stream is connected to a terminal. - * - * Reference: Composer\Util\Platform::isTty - * https://github.com/composer/composer - */ - private function isTty(): bool - { - // Detect msysgit/mingw and assume this is a tty because detection - // does not work correctly, see https://github.com/composer/composer/issues/9690 - if (\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) { - return true; - } - - return @stream_isatty($this->stream); - } } diff --git a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php index c06583f48383c..3e86e4ab49faa 100644 --- a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php @@ -613,7 +613,7 @@ private function hasColorSupport($stream): bool // 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; + return false; } if ('\\' === \DIRECTORY_SEPARATOR && @sapi_windows_vt100_support($stream)) {