From 8ec305a83aae199c0c08f4317e5b9b1894539fba 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 --- Output/StreamOutput.php | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Output/StreamOutput.php b/Output/StreamOutput.php index 95dc00a44..5f5ffce32 100644 --- a/Output/StreamOutput.php +++ b/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); - } }