mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
CLI/WIN
* support ansi escape codes for win 10 and up * also kill a warning
This commit is contained in:
@@ -12,9 +12,12 @@ else
|
||||
|
||||
mb_internal_encoding('UTF-8');
|
||||
|
||||
|
||||
// OS_WIN as per compile info of php
|
||||
define('OS_WIN', substr(PHP_OS, 0, 3) == 'WIN');
|
||||
|
||||
// WIN10 and later support ANSI escape sequences
|
||||
define('CLI_HAS_E', !OS_WIN || version_compare(php_uname('r'), '10.0') >= 0);
|
||||
|
||||
|
||||
require_once 'includes/defines.php';
|
||||
require_once 'includes/libs/DbSimple/Generic.php'; // Libraray: http://en.dklab.ru/lib/DbSimple (using variant: https://github.com/ivan1986/DbSimple/tree/master)
|
||||
|
||||
@@ -171,7 +171,7 @@ abstract class CLI
|
||||
$nCols = count($row);
|
||||
|
||||
for ($j = 0; $j < $nCols - 1; $j++) // don't pad last column
|
||||
$pads[$j] = max($pads[$j], mb_strlen($row[$j]));
|
||||
$pads[$j] = max($pads[$j] ?? 0, mb_strlen($row[$j]));
|
||||
}
|
||||
self::write();
|
||||
|
||||
@@ -214,27 +214,27 @@ abstract class CLI
|
||||
|
||||
public static function red(string $str) : string
|
||||
{
|
||||
return OS_WIN ? $str : "\e[31m".$str."\e[0m";
|
||||
return CLI_HAS_E ? "\e[31m".$str."\e[0m" : $str;
|
||||
}
|
||||
|
||||
public static function green(string $str) : string
|
||||
{
|
||||
return OS_WIN ? $str : "\e[32m".$str."\e[0m";
|
||||
return CLI_HAS_E ? "\e[32m".$str."\e[0m" : $str;
|
||||
}
|
||||
|
||||
public static function yellow(string $str) : string
|
||||
{
|
||||
return OS_WIN ? $str : "\e[33m".$str."\e[0m";
|
||||
return CLI_HAS_E ? "\e[33m".$str."\e[0m" : $str;
|
||||
}
|
||||
|
||||
public static function blue(string $str) : string
|
||||
{
|
||||
return OS_WIN ? $str : "\e[36m".$str."\e[0m";
|
||||
return CLI_HAS_E ? "\e[36m".$str."\e[0m" : $str;
|
||||
}
|
||||
|
||||
public static function bold(string $str) : string
|
||||
{
|
||||
return OS_WIN ? $str : "\e[1m".$str."\e[0m";
|
||||
return CLI_HAS_E ? "\e[1m".$str."\e[0m" : $str;
|
||||
}
|
||||
|
||||
public static function write(string $txt = '', int $lvl = self::LOG_BLANK, bool $timestamp = true, bool $tmpRow = false) : void
|
||||
@@ -267,7 +267,7 @@ abstract class CLI
|
||||
$msg .= $txt;
|
||||
}
|
||||
|
||||
$msg = (self::$overwriteLast && !OS_WIN ? "\e[1G\e[0K" : "\n") . $msg;
|
||||
$msg = (self::$overwriteLast && CLI_HAS_E ? "\e[1G\e[0K" : "\n") . $msg;
|
||||
self::$overwriteLast = $tmpRow;
|
||||
|
||||
echo $msg;
|
||||
|
||||
Reference in New Issue
Block a user