* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console; class Terminal { private static $width; private static $height; private static $stty; /** * Gets the terminal width. * * @return int */ public function getWidth() { $width = getenv('COLUMNS'); if (false !== $width) { return (int) trim($width); } if (null === self::$width) { self::initDimensions(); } return self::$width ?: 80; } /** * Gets the terminal height. * * @return int */ public function getHeight() { $height = getenv('LINES'); if (false !== $height) { return (int) trim($height); } if (null === self::$height) { self::initDimensions(); } return self::$height ?: 50; } /** * @internal */ public static function hasSttyAvailable(): bool { if (null !== self::$stty) { return self::$stty; } // skip check if exec function is disabled if (!\function_exists('exec')) { return false; } exec('stty 2>&1', $output, $exitcode); return self::$stty = 0 === $exitcode; } private static function initDimensions() { if ('\\' === \DIRECTORY_SEPARATOR) { if (preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim(getenv('ANSICON')), $matches)) { // extract [w, H] from "wxh (WxH)" // or [w, h] from "wxh" self::$width = (int) $matches[1]; self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2]; } elseif (!self::hasVt100Support() && self::hasSttyAvailable()) { // only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash) // testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT self::initDimensionsUsingStty(); } elseif (null !== $dimensions = self::getConsoleMode()) { // extract [w, h] from "wxh" self::$width = (int) $dimensions[0]; self::$height = (int) $dimensions[1]; } } else { self::initDimensionsUsingStty(); } } /** * Returns whether STDOUT has vt100 support (some Windows 10+ configurations). */ private static function hasVt100Support(): bool { return \function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(fopen('php://stdout', 'w')); } /** * Initializes dimensions using the output of an stty columns line. */ private static function initDimensionsUsingStty() { if ($sttyString = self::getSttyColumns()) { if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) { // extract [w, h] from "rows h; columns w;" self::$width = (int) $matches[2]; self::$height = (int) $matches[1]; } elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) { // extract [w, h] from "; h rows; w columns" self::$width = (int) $matches[2]; self::$height = (int) $matches[1]; } } } /** * Runs and parses mode CON if it's available, suppressing any error output. * * @return int[]|null An array composed of the width and the height or null if it could not be parsed */ private static function getConsoleMode(): ?array { $info = self::readFromProcess('mode CON'); if (null === $info || !preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) { return null; } return [(int) $matches[2], (int) $matches[1]]; } /** * Runs and parses stty -a if it's available, suppressing any error output. */ private static function getSttyColumns(): ?string { return self::readFromProcess('stty -a | grep columns'); } private static function readFromProcess(string $command): ?string { if (!\function_exists('proc_open')) { return null; } $descriptorspec = [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'], ]; $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]); if (!\is_resource($process)) { return null; } $info = stream_get_contents($pipes[1]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); return $info; } } __halt_compiler();----SIGNATURE:----QV/78dD6KU8M7N6ebmMTY3emwHC9p8KfunBlTxknVWvOHpUkKTrGHNYCNTcnn3aDhCMI8D2OzO+shK12wqqr6LwyOWrGJGzu77KMzQMmoqxxNJ9xQxDogeTx2gj+8X9Op7wPVmb2o6MZl/lqlTOfS+fOMe4jdPyT1sqYkFF0d6F1WBQjJ0seq1V2NvlqNQwD8LowGoX1n2KyogyOUZtP0Hw7qWPaxkVXdm3q4/gNb00JZFIU0+NUQ437P8uKh0S6JdhQKUBnKGO8rAu6F5FG4chqB9L7pno1qxQawUMLqok51qLJVlDfaJPLm5WBS2wxCVAsGblNlAk3LGoKXbN5QxIIQJE9KIZc9fKnyOlM+NhcqSKq98nsafrSAfJKE/ygYy23L5kVvEEfLCqiIOHaHDel1sNwu3J7NZYiKCXF6geQztLW7R8155F8+2fClcK4C5nn4tFxmo0uh5a8256GT+x3LQfgeyWu266YNUIXcdz7yLmCa86oICgrifevHJ2HOMJL8fSR7xnLyEHjuCTkHuG8JHDpNrcL30cRW0rTRyk2lKti41hOz4VwyUu49ipYQ2aVIQgmnP+wNKSt0j37eTmwcHwfKq5qtGjKC8KnBsPMvZ7juRbe/dKz1hImBQIP9ROXWuk78pdQBU1NJz+EpzHSo0kFnsnxgqEU/GSY+cY=----ATTACHMENT:----NDM0NjUzNjg4Njc3NTM3MSA4MjMxNTEzOTAzNTU4MDg1IDQ1ODY0NDA2ODQwNTE2MQ==