Automatically enable ANSI colours on Windows versions that support it

Note that stream_isatty() and sapi_windows_vt100_support() are ONLY defined on PHP 7.2, and the latter is only available on Windows.
This commit is contained in:
Dylan K. Taylor
2017-09-16 11:22:58 +01:00
parent 30d2318bb7
commit bdee746e46
2 changed files with 8 additions and 2 deletions

View File

@ -57,7 +57,13 @@ abstract class Terminal{
if(isset($opts["disable-ansi"])){
self::$formattingCodes = false;
}else{
self::$formattingCodes = ((Utils::getOS() !== "win" and getenv("TERM") != "" and (!function_exists("posix_ttyname") or !defined("STDOUT") or posix_ttyname(STDOUT) !== false)) or isset($opts["enable-ansi"]));
self::$formattingCodes = (isset($opts["enable-ansi"]) or ( //user explicitly told us to enable ANSI
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
)
));
}
}