Skip to content

Commit

Permalink
[PhpUnitBridge][VarDumper] fix color detection
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh authored and nicolas-grekas committed Feb 8, 2024
1 parent f5436ad commit 8ec305a
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}

0 comments on commit 8ec305a

Please sign in to comment.