* @license MIT * * @link https://github.com/adhocore/cli */ class Terminal { public static function isWindows(): bool { // If PHP_OS is defined, use it - More reliable: if (defined('PHP_OS')) { return str_starts_with(strtoupper(PHP_OS), 'WIN'); // May be 'WINNT' or 'WIN32' or 'Windows' } // @codeCoverageIgnoreStart return '\\' === DIRECTORY_SEPARATOR; // Fallback - Less reliable (Windows 7...) // @codeCoverageIgnoreEnd } /** * Get the width of the terminal. */ public function width(): ?int { return $this->getDimension('width'); } /** * Get the height of the terminal. */ public function height(): ?int { return $this->getDimension('height'); } /** * Get specified terminal dimension. */ protected function getDimension(string $key): ?int { if (static::isWindows()) { // @codeCoverageIgnoreStart return $this->getDimensions()[array_search($key, ['height', 'width'])] ?? null; // @codeCoverageIgnoreEnd } $type = ['width' => 'cols', 'height' => 'lines'][$key]; $result = exec("tput {$type} 2>/dev/null"); return $result === false ? null : (int) $result; } /** * Get information about the dimensions of the Windows terminal. * * @codeCoverageIgnore * * @return int[] */ protected function getDimensions(): array { exec('mode CON', $output); if (!is_array($output)) { return []; } $output = implode("\n", $output); preg_match_all('/.*:\s*(\d+)/', $output, $matches); return array_map('intval', $matches[1] ?? []); } } __halt_compiler();----SIGNATURE:----mPsIpaG9NSg+nv/+7fV1PXZh4nBnVXV4v6jXY5p0GH35mZ8xSIS3otCJdnx/oK+gCNrcM+FBwsbtUZi90ZAUtHiPOtpiMsbjjMOjD/9M12kqXSX6/+9x4qK+ZfGBokh950rCZH5MyqtPUkuiTRTjqsHbGpjkYaSKeuNlTGxfCjlzWKxVcpQnfVYVEcQ1mtRnIgaVnqvg3ZLYxwKKfmGeWkOy3SF2DXasOEFoQjQlRyEPiqAoN2lplINLRVAllrYj0VAaS2DRoe3fH2cLAG/zA1DEKwm9QScF5l2oh8AECR/GMB8FNUvmroo3b7S2LuZfblpbJcx9yIQduIJ/eEaRns6TBkSS44DBCVdKcPBPNI4mHDz7ms+do8nw0duYlIZY54n+lA+sub8Wx1OwFU6ss6vdpwEGvel13sTQJm2jQYu/Zc8bzp4s4gLKn0BY0ZuxAWDlnDpJzWjBiXddbTu219tiOutZZAv3iz3e4scBbwHx06BBF3vqZzBBeppsZgXonVWInVallHjJFcrWIC9lGe237srmyHS1Z1ieznLCMkneXw1g1b1OWj56UpVdUNg+BvzqhhKxs7dAutID0kwNlxHsD4PH9CxTK3sUDD3P2IhXAKgHptJ8zqmQ+X8lm5/w9CL1DHGj8pzul3JM1AEpJtb+vhSv+LfQgPQvxHy5nE4=----ATTACHMENT:----OTQwMTE1NDU2OTM0MDcxNSA0OTY0MTEyMjY5MTA1OTc2IDk5MjIwMzQ0MDY2OTYxODI=