Skip to content

Commit 4074601

Browse files
minor #53794 [PhpUnitBridge][VarDumper] Fix color detection (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [PhpUnitBridge][VarDumper] Fix color detection | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Porting #53707 to VarDumper and tweaking it a bit. /cc `@theofidry` FYI Commits ------- 7ce86dcfee [VarDumper][PhpUnitBridge] Fix color detection
2 parents 7ae060a + 7265b71 commit 4074601

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Dumper/CliDumper.php

+19-8
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,30 @@ private function hasColorSupport($stream): bool
610610
return false;
611611
}
612612

613-
if ('Hyper' === getenv('TERM_PROGRAM')) {
613+
// Detect msysgit/mingw and assume this is a tty because detection
614+
// does not work correctly, see https://github.com/composer/composer/issues/9690
615+
if (!@stream_isatty($stream) && !\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) {
614616
return true;
615617
}
616618

617-
if (\DIRECTORY_SEPARATOR === '\\') {
618-
return (\function_exists('sapi_windows_vt100_support')
619-
&& @sapi_windows_vt100_support($stream))
620-
|| false !== getenv('ANSICON')
621-
|| 'ON' === getenv('ConEmuANSI')
622-
|| 'xterm' === getenv('TERM');
619+
if ('\\' === \DIRECTORY_SEPARATOR && @sapi_windows_vt100_support($stream)) {
620+
return true;
621+
}
622+
623+
if ('Hyper' === getenv('TERM_PROGRAM')
624+
|| false !== getenv('COLORTERM')
625+
|| false !== getenv('ANSICON')
626+
|| 'ON' === getenv('ConEmuANSI')
627+
) {
628+
return true;
629+
}
630+
631+
if ('dumb' === $term = (string) getenv('TERM')) {
632+
return false;
623633
}
624634

625-
return stream_isatty($stream);
635+
// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
636+
return preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
626637
}
627638

628639
/**

0 commit comments

Comments
 (0)