pocketmine\utils\Terminal::hasFormattingCodes PHP Method

hasFormattingCodes() public static method

public static hasFormattingCodes ( )
    public static function hasFormattingCodes()
    {
        if (self::$formattingCodes === null) {
            $opts = getopt("", ["enable-ansi", "disable-ansi"]);
            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"]));
            }
        }
        return self::$formattingCodes;
    }

Usage Example

Example #1
0
 private function titleTick()
 {
     if (!Terminal::hasFormattingCodes()) {
         return;
     }
     $d = Utils::getRealMemoryUsage();
     $u = Utils::getMemoryUsage(true);
     $usage = round($u[0] / 1024 / 1024, 2) . "/" . round($d[0] / 1024 / 1024, 2) . "/" . round($u[1] / 1024 / 1024, 2) . "/" . round($u[2] / 1024 / 1024, 2) . " MB @ " . Utils::getThreadCount() . " threads";
     echo "]0;" . $this->getName() . " " . $this->getPocketMineVersion() . " | Online " . count($this->players) . "/" . $this->getMaxPlayers() . " | Memory " . $usage . " | U " . round($this->network->getUpload() / 1024, 2) . " D " . round($this->network->getDownload() / 1024, 2) . " kB/s | TPS " . $this->getTicksPerSecond() . " | Load " . $this->getTickUsage() . "%";
     $this->network->resetStatistics();
 }
All Usage Examples Of pocketmine\utils\Terminal::hasFormattingCodes