Skip to content

Commit d485a66

Browse files
wdoekesnicolas-grekas
authored andcommitted
[Console] fewer syscalls when fetching $LINES/$COLUMNS
1 parent f3851b7 commit d485a66

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Terminal.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ private static function hasVt100Support(): bool
143143
private static function initDimensionsUsingStty()
144144
{
145145
if ($sttyString = self::getSttyColumns()) {
146-
if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
146+
if (preg_match('/rows.(\d+);.columns.(\d+);/is', $sttyString, $matches)) {
147147
// extract [w, h] from "rows h; columns w;"
148148
self::$width = (int) $matches[2];
149149
self::$height = (int) $matches[1];
150-
} elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
150+
} elseif (preg_match('/;.(\d+).rows;.(\d+).columns/is', $sttyString, $matches)) {
151151
// extract [w, h] from "; h rows; w columns"
152152
self::$width = (int) $matches[2];
153153
self::$height = (int) $matches[1];
@@ -176,10 +176,10 @@ private static function getConsoleMode(): ?array
176176
*/
177177
private static function getSttyColumns(): ?string
178178
{
179-
return self::readFromProcess('stty -a | grep columns');
179+
return self::readFromProcess(['stty', '-a']);
180180
}
181181

182-
private static function readFromProcess(string $command): ?string
182+
private static function readFromProcess(string|array $command): ?string
183183
{
184184
if (!\function_exists('proc_open')) {
185185
return null;

0 commit comments

Comments
 (0)