Skip to content

Commit

Permalink
Fix "Argument #1 ($string) must be of type string, bool given" (#11)
Browse files Browse the repository at this point in the history
* Fix "Argument #1 ($string) must be of type string, bool given"

* Update Terminal.php

* extract method

* Update Terminal.php

* Update Terminal.php
  • Loading branch information
staabm authored Nov 11, 2024
1 parent f88ab09 commit 072f9f7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Console/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ private static function initDimensions(): void
$consoleMode = self::getConsoleMode();

if ('\\' === \DIRECTORY_SEPARATOR) {
if (\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) {
Expand Down Expand Up @@ -123,4 +124,17 @@ private static function readFromProcess(string $command): ?string
\proc_close($process);
return $info;
}

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

0 comments on commit 072f9f7

Please sign in to comment.