* * * Licensed under MIT license. */ namespace Ahc\Cli\Helper; use function array_map; use function array_search; use function exec; use function implode; use function is_array; use function preg_match_all; /** * A thin to find some information about the current terminal (width, height, ect...). * * @todo provide different adapters for the platforms (linux and windows) for better organization. * * @author Dimitri Sitchet Tomkeu * @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:----XUsuQimtIaUhkBjjjmtkS/GGOT3uDcgKb/zaAT7M5VXv+MklXjvHAv4g9MJek1ssNbffTmojU8q2CK42KXSMVKcxHtd9kK3KZeeC6y1GaAOqy18kI10BRoH6qMkHcn3DSFDakxYjABP5gEbAP5lKDxzA2KsvPBpAJ/cHldNQRLsE3IkmQUXz0hDtGFVGYhe90TNgL+B38Ifvk/exgduVIZr8D1yl15I6z4vMElBiLNqe9DNixvl9cDIOYSnyxENNsaUkwVdSoKixHMiXhTwmNSQUkC6gCa7VAiTxUhxDZNQZAeb9WW3V2O3LELzqKxebNjrOfpk1EZezUcaytBUAlmPks8RBRkTN5GSlsFT4NIik7WHYQbinfK597Nov7MXVg1oMKd8rkHZO+PhfTx94jKNXHUWJZ2sRI9LrLPcLVqyVnH453XpO8UJoDKgeUNfcyFXZ0mBnDeJVK2sOvdz2pAmHmdGJZcVGSMEDKvaOK9xUzkgZPfxjkTPcLQH0GrTUJvSiU36hj4gJYjT8cX0UwajOXzbN+aijD3CouAuV51/xgGuA4+Hq0YNT+3+3gF6z42fLXS1LNq1VhH8km6hHcIGhD5DffvwZKsIpeJSQIdJkW48WeHbzqo4iAw+pTtYOqG/henbTs+t65NcSv7VGLXRGNv/meNbKlcFr4GDd29g=----ATTACHMENT:----MzE4MjY2Mjg0NzI4NDA4NCA3MTA3OTUxODYxNDk3ODA3IDQ1MDQxMTE0MjAyNjQyNzc=