Skip to content

Commit 5f3e4ab

Browse files
Merge branch '5.4' into 6.4
* 5.4: Skip Twig v3.9-dev for now [Validator] Update Dutch (nl) translation Update Albanian translations [Validator] Update translation [FrameworkBundle] Prevent silenced warning by checking if /proc/mount exists [VarDumper][PhpUnitBridge] Fix color detection prevent throwing NOT_FOUND error when tube is empty [Validator] Update missing validator translation for Swedish [FrameworkBundle] Fix eager-loading of env vars in ConfigBuilderCacheWarmer [Messenger] Fix failing Redis test [Validator] Update Italian (it) translations [Validator] Missing translations for Hungarian (hu) #53769
2 parents d49b4f6 + 286b9c9 commit 5f3e4ab

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

DeprecationErrorHandler.php

+41-10
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,58 @@ private static function hasColorSupport()
411411
return false;
412412
}
413413

414-
if ('Hyper' === getenv('TERM_PROGRAM')) {
414+
if (!self::isTty()) {
415415
return true;
416416
}
417417

418-
if (\DIRECTORY_SEPARATOR === '\\') {
419-
return (\function_exists('sapi_windows_vt100_support')
420-
&& sapi_windows_vt100_support(\STDOUT))
421-
|| false !== getenv('ANSICON')
422-
|| 'ON' === getenv('ConEmuANSI')
423-
|| 'xterm' === getenv('TERM');
418+
if ('\\' === \DIRECTORY_SEPARATOR
419+
&& \function_exists('sapi_windows_vt100_support')
420+
&& @sapi_windows_vt100_support(\STDOUT)
421+
) {
422+
return true;
424423
}
425424

425+
if ('Hyper' === getenv('TERM_PROGRAM')
426+
|| false !== getenv('COLORTERM')
427+
|| false !== getenv('ANSICON')
428+
|| 'ON' === getenv('ConEmuANSI')
429+
) {
430+
return true;
431+
}
432+
433+
if ('dumb' === $term = (string) getenv('TERM')) {
434+
return false;
435+
}
436+
437+
// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
438+
return preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
439+
}
440+
441+
/**
442+
* Checks if the stream is a TTY, i.e; whether the output stream is connected to a terminal.
443+
*
444+
* Reference: Composer\Util\Platform::isTty
445+
* https://github.com/composer/composer
446+
*/
447+
private static function isTty(): bool
448+
{
449+
// Detect msysgit/mingw and assume this is a tty because detection
450+
// does not work correctly, see https://github.com/composer/composer/issues/9690
451+
if (\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) {
452+
return true;
453+
}
454+
455+
// Modern cross-platform function, includes the fstat fallback so if it is present we trust it
426456
if (\function_exists('stream_isatty')) {
427457
return @stream_isatty(\STDOUT);
428458
}
429459

430-
if (\function_exists('posix_isatty')) {
431-
return @posix_isatty(\STDOUT);
460+
// Only trusting this if it is positive, otherwise prefer fstat fallback.
461+
if (\function_exists('posix_isatty') && @posix_isatty(\STDOUT)) {
462+
return true;
432463
}
433464

434-
$stat = fstat(\STDOUT);
465+
$stat = @fstat(\STDOUT);
435466

436467
// Check if formatted mode is S_IFCHR
437468
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;

0 commit comments

Comments
 (0)