From bdee746e4615ad941c7c0543608d774900c8d184 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 16 Sep 2017 11:22:58 +0100 Subject: [PATCH] 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. --- src/pocketmine/utils/Terminal.php | 8 +++++++- start.ps1 | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/utils/Terminal.php b/src/pocketmine/utils/Terminal.php index 3fec7fcb0..0b53c2ef3 100644 --- a/src/pocketmine/utils/Terminal.php +++ b/src/pocketmine/utils/Terminal.php @@ -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 + ) + )); } } diff --git a/start.ps1 b/start.ps1 index 9c0cf318f..b7f1890ab 100644 --- a/start.ps1 +++ b/start.ps1 @@ -25,7 +25,7 @@ if(Test-Path "PocketMine-MP.phar"){ } function StartServer{ - $command = "powershell " + $binary + " " + $file + " --enable-ansi " + $extraPocketMineArgs + $command = "powershell " + $binary + " " + $file + " " + $extraPocketMineArgs iex $command }