mirror of
https://github.com/zhamao-robot/zhamao-logger.git
synced 2026-03-17 20:44:52 +08:00
add terminal size caching
This commit is contained in:
parent
c14e6b75b8
commit
bcc6a9b4e4
@ -10,7 +10,7 @@ $data = [
|
||||
'php_version_id' => PHP_VERSION_ID,
|
||||
'info' => '并且支持中文!!',
|
||||
'path2' => __DIR__,
|
||||
'long' => '我可以' . str_repeat('很长', 50),
|
||||
'中文级别的key' => '我可以' . str_repeat('很长', 50),
|
||||
];
|
||||
|
||||
(new \ZM\Logger\TablePrinter($data))
|
||||
|
||||
@ -41,6 +41,8 @@ class TablePrinter
|
||||
*/
|
||||
protected $row_overflow_hide = false;
|
||||
|
||||
protected $terminal_size;
|
||||
|
||||
public function __construct(array $params, string $head = '=', string $foot = '=', int $max_border_length = 79)
|
||||
{
|
||||
$this->params = $params;
|
||||
@ -216,16 +218,19 @@ class TablePrinter
|
||||
*
|
||||
* @return int 终端大小
|
||||
*/
|
||||
private function fetchTerminalSize(): int
|
||||
public function fetchTerminalSize(): int
|
||||
{
|
||||
if (!isset($this->terminal_size)) {
|
||||
if (STDIN === false) {
|
||||
return 79;
|
||||
return $this->terminal_size = 79;
|
||||
}
|
||||
$size = exec('stty size 2>/dev/null');
|
||||
if (empty($size)) {
|
||||
return 79;
|
||||
return $this->terminal_size = 79;
|
||||
}
|
||||
return (int) explode(' ', trim($size))[1];
|
||||
return $this->terminal_size = (int) explode(' ', trim($size))[1];
|
||||
}
|
||||
return $this->terminal_size;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user