* @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:----0d+fr+rORP5SLtheYYwk4Gvj1a5+gcXwUpbqJwh2Qm609ff307rXXQuaR7vrjFIYAdDMgi33qBbbFlKw90tTIjMmdxWC0HVdMIdIVS81CQ68CJwcIKCFneWdIRkWDJzg7lb2JXZJuWUWYQL8n2aL2xc8e9EOu5tYuQDkMTK4KUT3HBYCC6cljEbxV/kmNDi7ffeVmGt6MVLH0RcnegkdHP3psEindivW9fZ9bfV6Vbjo1hSSEE2Xtg5pBecvU4AEsOk5QvJNrL6wvVwKLrZ33J7Ld9ZwpmOMd1IGfFnVfIWufhF7GZcgaeUGD7E1asd5LPYJsN702bGrCDHCP12JIKb9Y7pbulPW1D0+zeQrluHm8+zamLhYzgNSvaXl9z4YjmMesRogJk57bGjGW0XyjeVuUyCfM1zb5aM3OJ8DyRLuS/wO2bSRhMnP9VUoU9neJz2F2nIhG0VCQoyM2+tqHR9XREs8S51lcGa2FgokYt/m468th6gP4dlzf/W4GnYLbDKLEE2imtiuwrXLnQ1rdwSv0Oab+9vC8d378gleiQ6YxE7EF77Jj/cbymqnfGzeRk74CFU3pzu/yVNbSUTD+omA9hxpHHdSao73C3CKiVdZVKnKCE3mgEXYty48wH4iKfrRgrdJPlNUXndfWUV1c5tQi7ZwzEHCXnMdd6LLlyo=----ATTACHMENT:----NDg5ODg5ODgxODU1MjM2MSA0NjE0NTYzODk2MDMzMTQ5IDg0MTMwMTAyNTAxODIzMjY=