From 25154cf568340544927e7cf457c0d1345176b965 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 11 Nov 2024 09:39:18 +0100 Subject: [PATCH 1/5] Fix "Argument #1 ($string) must be of type string, bool given" --- src/Console/Terminal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Terminal.php b/src/Console/Terminal.php index 8b585bf3..1e438135 100644 --- a/src/Console/Terminal.php +++ b/src/Console/Terminal.php @@ -54,7 +54,7 @@ private static function initDimensions(): void { $consoleMode = self::getConsoleMode(); - if ('\\' === \DIRECTORY_SEPARATOR) { + if ('\\' === \DIRECTORY_SEPARATOR && is_string(\getenv('ANSICON'))) { if (\preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) { self::$width = (int) $matches[1]; } elseif (! self::hasVt100Support() && self::hasSttyAvailable()) { From 99dc70af39c153528dfa3beed3b00267571a1c4f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 11 Nov 2024 09:40:29 +0100 Subject: [PATCH 2/5] Update Terminal.php --- src/Console/Terminal.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Terminal.php b/src/Console/Terminal.php index 1e438135..2290331e 100644 --- a/src/Console/Terminal.php +++ b/src/Console/Terminal.php @@ -54,8 +54,8 @@ private static function initDimensions(): void { $consoleMode = self::getConsoleMode(); - if ('\\' === \DIRECTORY_SEPARATOR && is_string(\getenv('ANSICON'))) { - if (\preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) { + if ('\\' === \DIRECTORY_SEPARATOR) { + if (is_string(\getenv('ANSICON')) && \preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) { self::$width = (int) $matches[1]; } elseif (! self::hasVt100Support() && self::hasSttyAvailable()) { self::initDimensionsUsingStty(); From 9ca35e66798767466fe5ca4575c04f6ad576fce7 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 11 Nov 2024 10:11:40 +0100 Subject: [PATCH 3/5] extract method --- src/Console/Terminal.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Console/Terminal.php b/src/Console/Terminal.php index 2290331e..35aac07b 100644 --- a/src/Console/Terminal.php +++ b/src/Console/Terminal.php @@ -55,8 +55,9 @@ private static function initDimensions(): void $consoleMode = self::getConsoleMode(); if ('\\' === \DIRECTORY_SEPARATOR) { - if (is_string(\getenv('ANSICON')) && \preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) { - self::$width = (int) $matches[1]; + $width = self::getAnsiconWidth(); + if ($width === null) { + self::$width = $width; } elseif (! self::hasVt100Support() && self::hasSttyAvailable()) { self::initDimensionsUsingStty(); } elseif ($consoleMode) { @@ -123,4 +124,17 @@ private static function readFromProcess(string $command): ?string \proc_close($process); return $info; } + + public static function getAnsiconWidth(): ?int + { + if (!is_string(\getenv('ANSICON'))) { + return null; + } + + if (\preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) { + return (int) $matches[1]; + } + + return null; + } } From 337394431fb86e22d1d351eae4d4d9e9c458f3e3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 11 Nov 2024 10:12:20 +0100 Subject: [PATCH 4/5] Update Terminal.php --- src/Console/Terminal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Terminal.php b/src/Console/Terminal.php index 35aac07b..8761d97d 100644 --- a/src/Console/Terminal.php +++ b/src/Console/Terminal.php @@ -56,7 +56,7 @@ private static function initDimensions(): void if ('\\' === \DIRECTORY_SEPARATOR) { $width = self::getAnsiconWidth(); - if ($width === null) { + if ($width !== null) { self::$width = $width; } elseif (! self::hasVt100Support() && self::hasSttyAvailable()) { self::initDimensionsUsingStty(); From 79b78c842b4976205490d5c854dad778949bd450 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 11 Nov 2024 10:13:01 +0100 Subject: [PATCH 5/5] Update Terminal.php --- src/Console/Terminal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Terminal.php b/src/Console/Terminal.php index 8761d97d..f2c956ad 100644 --- a/src/Console/Terminal.php +++ b/src/Console/Terminal.php @@ -125,7 +125,7 @@ private static function readFromProcess(string $command): ?string return $info; } - public static function getAnsiconWidth(): ?int + private static function getAnsiconWidth(): ?int { if (!is_string(\getenv('ANSICON'))) { return null;