* @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:----R4NIYU4E5FznHYekiLCD+HvbMhw7cfKkhWAJNq8N/xKWtUrKIJhrVQovHdhCFNkNQsjDTfomWfmRQOvMlf5ei/u0ZoT1tw7DJYdvbcu3DB1KC311hSGyfjARNL6NYg9ZLY9inG/1KUyWApt33WEHcBy4Eq/ya9F30vHqaiJVTMZSp4a3OVbRcpoj6eg1QxAm5O59a+nZD3ab2vu+5q99vcUB/pzk9hlqlxM0N+uKxyk1WGxXEqcIOMohFO/v7/bj8jZ9xwUuryQ0l/2dWKKkmjGZptdfLXT3nQsHRoLAvCST7C5WFX3lqmXZIN3/N9m+8agzdmzD4qbLdMSHbilUNiBNY++gwc46ajRVTBde/TUkpONfzCSLV4+wVAzCFf2O7Nh7z3Gq8GoYG2mO2+daz8ZOvrx5O4m7psRKA++K7Zt4lIeI1zQTiN91VIVorG6JYPyUnKYYk+9etO6FH5O8HF+WoCMTUYfb7VRiBq+WJ2X5q58D/ixhDJ+/+oaiTAeanzc5dK7EQoW0JTN8YJvmLEVIbw1tTo4QXnj5TpR5vSblnjQMk0OA2fkrcaYWwta7EUmgI8UEqsB42uFjW1LDB40XKOlGSt0o6NWuRQHXH40u2O6lMGtZ03KZ+/Ht9rZ56Nia+bAImEzIuUOy0OBm+tFsJ+/O1+HfDfLlwJuTiLs=----ATTACHMENT:----ODI3MTM5NjA1MTM5MzQwNyAyNzcxMjAzNDA2ODg5MTM0IDkzNTYyNzAyMTE3NTIwMTk=