You are here

public function Application::getTerminalDimensions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Application.php \Symfony\Component\Console\Application::getTerminalDimensions()

Tries to figure out the terminal dimensions based on the current environment.

Return value

array Array containing width and height

2 calls to Application::getTerminalDimensions()
Application::getTerminalHeight in vendor/symfony/console/Application.php
Tries to figure out the terminal height in which this application runs.
Application::getTerminalWidth in vendor/symfony/console/Application.php
Tries to figure out the terminal width in which this application runs.

File

vendor/symfony/console/Application.php, line 731

Class

Application
An Application is the container for a collection of commands.

Namespace

Symfony\Component\Console

Code

public function getTerminalDimensions() {
  if ($this->terminalDimensions) {
    return $this->terminalDimensions;
  }
  if ('\\' === DIRECTORY_SEPARATOR) {

    // extract [w, H] from "wxh (WxH)"
    if (preg_match('/^(\\d+)x\\d+ \\(\\d+x(\\d+)\\)$/', trim(getenv('ANSICON')), $matches)) {
      return array(
        (int) $matches[1],
        (int) $matches[2],
      );
    }

    // extract [w, h] from "wxh"
    if (preg_match('/^(\\d+)x(\\d+)$/', $this
      ->getConsoleMode(), $matches)) {
      return array(
        (int) $matches[1],
        (int) $matches[2],
      );
    }
  }
  if ($sttyString = $this
    ->getSttyColumns()) {

    // extract [w, h] from "rows h; columns w;"
    if (preg_match('/rows.(\\d+);.columns.(\\d+);/i', $sttyString, $matches)) {
      return array(
        (int) $matches[2],
        (int) $matches[1],
      );
    }

    // extract [w, h] from "; h rows; w columns"
    if (preg_match('/;.(\\d+).rows;.(\\d+).columns/i', $sttyString, $matches)) {
      return array(
        (int) $matches[2],
        (int) $matches[1],
      );
    }
  }
  return array(
    null,
    null,
  );
}