Terminal::hasFormattingCodes() workaround for STDOUT not being defined

#1979

This isn't a full solution because formatting codes are still not applied correctly if the calling thread doesn't inherit classes.
This commit is contained in:
Dylan K. Taylor 2018-01-30 10:53:43 +00:00
parent d2d1df0447
commit c601816586

View File

@ -57,13 +57,15 @@ abstract class Terminal{
if(isset($opts["disable-ansi"])){
self::$formattingCodes = false;
}else{
$stdout = fopen("php://stdout", "w");
self::$formattingCodes = (isset($opts["enable-ansi"]) or ( //user explicitly told us to enable ANSI
stream_isatty(STDOUT) and //STDOUT isn't being piped
stream_isatty($stdout) and //STDOUT isn't being piped
(
getenv('TERM') !== false or //Console says it supports colours
(function_exists('sapi_windows_vt100_support') and sapi_windows_vt100_support(STDOUT)) //we're on windows and have vt100 support
(function_exists('sapi_windows_vt100_support') and sapi_windows_vt100_support($stdout)) //we're on windows and have vt100 support
)
));
fclose($stdout);
}
}