Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c91f667

Browse filesBrowse files
committed
fix color detection
1 parent fa7531f commit c91f667
Copy full SHA for c91f667

File tree

Expand file treeCollapse file tree

2 files changed

+33
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-5
lines changed

‎src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ private static function hasColorSupport()
404404
}
405405

406406
if (!self::isTty()) {
407-
return true;
407+
return false;
408408
}
409409

410410
if ('\\' === \DIRECTORY_SEPARATOR

‎src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Dumper/CliDumper.php
+32-4Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,8 @@ private function hasColorSupport($stream): bool
610610
return false;
611611
}
612612

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)) {
616-
return true;
613+
if (!self::isTty()) {
614+
return false;
617615
}
618616

619617
if ('\\' === \DIRECTORY_SEPARATOR && @sapi_windows_vt100_support($stream)) {
@@ -636,6 +634,36 @@ private function hasColorSupport($stream): bool
636634
return preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
637635
}
638636

637+
/**
638+
* Checks if the stream is a TTY, i.e; whether the output stream is connected to a terminal.
639+
*
640+
* Reference: Composer\Util\Platform::isTty
641+
* https://github.com/composer/composer
642+
*/
643+
private static function isTty(): bool
644+
{
645+
// Detect msysgit/mingw and assume this is a tty because detection
646+
// does not work correctly, see https://github.com/composer/composer/issues/9690
647+
if (\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) {
648+
return true;
649+
}
650+
651+
// Modern cross-platform function, includes the fstat fallback so if it is present we trust it
652+
if (\function_exists('stream_isatty')) {
653+
return @stream_isatty(\STDOUT);
654+
}
655+
656+
// Only trusting this if it is positive, otherwise prefer fstat fallback.
657+
if (\function_exists('posix_isatty') && @posix_isatty(\STDOUT)) {
658+
return true;
659+
}
660+
661+
$stat = @fstat(\STDOUT);
662+
663+
// Check if formatted mode is S_IFCHR
664+
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
665+
}
666+
639667
/**
640668
* Returns true if the Windows terminal supports true color.
641669
*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.