Skip to content

Commit

Permalink
[VarDumper][PhpUnitBridge] Fix color detection
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Feb 5, 2024
1 parent ce4685b commit 7265b71
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Dumper/CliDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,19 +610,30 @@ private function hasColorSupport($stream): bool
return false;
}

if ('Hyper' === getenv('TERM_PROGRAM')) {
// 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;
}

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 ('\\' === \DIRECTORY_SEPARATOR && @sapi_windows_vt100_support($stream)) {
return true;
}

if ('Hyper' === getenv('TERM_PROGRAM')
|| false !== getenv('COLORTERM')
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
) {
return true;
}

if ('dumb' === $term = (string) getenv('TERM')) {
return false;
}

return stream_isatty($stream);
// 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);
}

/**
Expand Down

0 comments on commit 7265b71

Please sign in to comment.