From cc43c4729f066947784b51f6af38fa996bd5e5f6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 22 Aug 2022 13:07:48 +0800 Subject: [PATCH] update to 1.0.1 (add windows support) --- src/ZM/Logger/ConsoleLogger.php | 2 +- src/ZM/Logger/TablePrinter.php | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ZM/Logger/ConsoleLogger.php b/src/ZM/Logger/ConsoleLogger.php index 65b8ec7..1a6e1a6 100644 --- a/src/ZM/Logger/ConsoleLogger.php +++ b/src/ZM/Logger/ConsoleLogger.php @@ -10,7 +10,7 @@ use Psr\Log\LogLevel; class ConsoleLogger extends AbstractLogger { - public const VERSION = '1.0.0-alpha'; + public const VERSION = '1.0.1'; /** * 日志输出格式 diff --git a/src/ZM/Logger/TablePrinter.php b/src/ZM/Logger/TablePrinter.php index af327e0..f4f9d3a 100644 --- a/src/ZM/Logger/TablePrinter.php +++ b/src/ZM/Logger/TablePrinter.php @@ -221,14 +221,28 @@ class TablePrinter public function fetchTerminalSize(): int { if (!isset($this->terminal_size)) { + /* @phpstan-ignore-next-line */ if (STDIN === false) { return $this->terminal_size = 79; } - $size = exec('stty size 2>/dev/null'); + $size = 0; + if (DIRECTORY_SEPARATOR === '\\') { + exec('mode con', $out); + foreach ($out as $v) { + if (strpos($v, 'Columns:') !== false) { + $num = trim(explode('Columns:', $v)[1]); + $size = intval($num); + break; + } + } + } else { + $size = exec('stty size 2>/dev/null'); + $size = (int) explode(' ', trim($size))[1]; + } if (empty($size)) { return $this->terminal_size = 79; } - return $this->terminal_size = (int) explode(' ', trim($size))[1]; + return $this->terminal_size = $size; } return $this->terminal_size; }