Skip to content

Commit 8e93803

Browse files
committed
Environment: improved color detection
- on Windows rely on sapi_windows_vt100_support() - on Linux rely on stream_isatty() - respects NO_COLOR and FORCE_COLOR
1 parent 937ae82 commit 8e93803

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/Framework/Environment.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,12 @@ public static function setupColors(): void
7878
self::$useColors = getenv(self::COLORS) !== false
7979
? (bool) getenv(self::COLORS)
8080
: (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')
81-
&& (!function_exists('stream_isatty') || stream_isatty(STDOUT)) // PHP >= 7.2
82-
&& getenv('NO_COLOR') === false
83-
&& (defined('PHP_WINDOWS_VERSION_BUILD')
84-
? (function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT))
85-
|| getenv('ConEmuANSI') === 'ON' // ConEmu
86-
|| getenv('ANSICON') !== false // ANSICON
87-
|| getenv('term') === 'xterm' // MSYS
88-
|| getenv('term') === 'xterm-256color' // MSYS
89-
: (!function_exists('posix_isatty') || posix_isatty(STDOUT))); // PHP < 7.2
81+
&& getenv('NO_COLOR') === false // https://no-color.org
82+
&& (getenv('FORCE_COLOR')
83+
|| (function_exists('sapi_windows_vt100_support')
84+
? sapi_windows_vt100_support(STDOUT)
85+
: @stream_isatty(STDOUT)) // @ may trigger error 'cannot cast a filtered stream on this system'
86+
);
9087

9188
ob_start(function (string $s): string {
9289
return self::$useColors ? $s : Dumper::removeColors($s);

0 commit comments

Comments
 (0)