* * 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:----WOkD5RpsZ4L2uK/qxRiLZMemAdVAJi+B9tCjpH6/51qE0+b7MoSBbnmCX7vWYoPc0LA6vqopKs/YkkXy8yBd+qr0h8cVmm03yqO69HxHEfVPpWKwQS15CK7/zBjdrhOhIK0/7QB6Evm8kBw1BhKBMd442/9kRkmkLnezOHYnidjrmjHP2IdRApV8Gwhv6WI13aP+AY3RP4MmJGVcReut4RVAMAIwZyf0xHbSdjzgskjwZOyjPIBHmRysCtsTrc/XkYVUY9ToMCdSDihpxiFATBXgb96kcy9bImG4+IO77Q60ubOVGgXmTnRE+MuP7MM0jHjNnsF9/xV+Fn9q1gufLDpPUWF4DXpBFci1xbD0HdH3e9pr14IEsoz4VmGBxYHq5W8yRFQ4HAzs3kBfExwJ8QrT1nW813gCTCEzj3R3tl1eAxcCEMSt0PUSMpKGblo7uprg0V2CbmIDX6oL+tfUYDlk0UE5Ux0p6gWXX1oXUUvaPXJjXIwNyRKg2QsHfxMWDvuy63WdT8Ih6vZwT+QfLIw2ht3e/Jaqu7VbuWM9jz/Fn5yyoBa9D7HDKte1DYW7IPgj3shquCqzSxh/abKEtWucErVIpsQ3JYWlYsvrH6P5w6AJnyMtPMsyVcoI6OnZbkQeR+JuhkvA9lJy7jE/WTHAFKvdC8R6qKIGcZJlULw=----ATTACHMENT:----NzgxMDg0MDE2NzE0MjAyIDI4NDUxODQ3ODExNDAyODIgNTQwMjg5Mjc5NTcxOTM=