diff --git a/src/Console/Terminal.php b/src/Console/Terminal.php index 8b585bf3..f2c956ad 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 (\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; } + + 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; + } }