update to 1.0.1 (add windows support)

This commit is contained in:
crazywhalecc 2022-08-22 13:07:48 +08:00 committed by Jerry Ma
parent af263a9d3b
commit cc43c4729f
2 changed files with 17 additions and 3 deletions

View File

@ -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';
/**
* 日志输出格式

View File

@ -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;
}