Permalink
Browse files

Merge branch '2.1'

* 2.1:
  [Console] made Application::getTerminalDimensions() public
  Revert "merged branch egeloen/f-2.0-terminal-width (PR #6571)"
  [2.1] [Console] Added getTerminalDimensions() with fix for osx/freebsd
  Restrict Monolog version to be in version `<1.3`. Because of conflict between `HttpKernel/Log/LoggerInterface` and `Psr\Log\LoggerInterface` (PSR-3)

Conflicts:
	composer.json
  • Loading branch information...
2 parents af07008 + d786e09 commit 583d999b4e0169cfad884f27ab759cde6bbb5c58 @fabpot fabpot committed Jan 5, 2013
Showing with 36 additions and 24 deletions.
  1. +1 −1 composer.json
  2. +35 −23 src/Symfony/Component/Console/Application.php
View
@@ -59,7 +59,7 @@
"doctrine/data-fixtures": "1.0.*",
"doctrine/dbal": ">=2.2,<2.4-dev",
"doctrine/orm": ">=2.2.3,<2.4-dev",
- "monolog/monolog": "1.*",
+ "monolog/monolog": ">=1.0,<1.3-dev",
"propel/propel1": "dev-master"
},
"autoload": {
@@ -797,7 +797,7 @@ public function renderException($e, $output)
$len = $strlen($title);
$width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
$lines = array();
- foreach (preg_split("{\r?\n}", $e->getMessage()) as $line) {
+ foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
foreach (str_split($line, $width - 4) as $line) {
$lines[] = sprintf(' %s ', $line);
$len = max($strlen($line) + 4, $len);
@@ -859,43 +859,55 @@ public function renderException($e, $output)
*
* @return int|null
*/
- public function getTerminalWidth()
+ protected function getTerminalWidth()
{
- if (defined('PHP_WINDOWS_VERSION_BUILD')) {
- if ($ansicon = getenv('ANSICON')) {
- return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
- }
-
- if (preg_match('{^(\d+)x\d+$}i', $this->getConsoleMode(), $matches)) {
- return $matches[1];
- }
- }
+ $dimensions = $this->getTerminalDimensions();
- if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {
- return $match[2];
- }
+ return $dimensions[0];
}
/**
* Tries to figure out the terminal height in which this application runs
*
* @return int|null
*/
- public function getTerminalHeight()
+ protected function getTerminalHeight()
+ {
+ $dimensions = $this->getTerminalDimensions();
+
+ return $dimensions[1];
+ }
+
+ /**
+ * Tries to figure out the terminal dimensions based on the current environment
+ *
+ * @return array Array containing width and height
+ */
+ public function getTerminalDimensions()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
- if ($ansicon = getenv('ANSICON')) {
- return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
+ // 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]);
}
-
- if (preg_match('{^\d+x(\d+)$}i', $this->getConsoleMode(), $matches)) {
- return $matches[1];
+ // extract [w, h] from "wxh"
+ if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) {
+ return array((int) $matches[1], (int) $matches[2]);
}
}
- if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {
- return $match[1];
+ 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);
}
/**
@@ -996,7 +1008,7 @@ private function getConsoleMode()
fclose($pipes[2]);
proc_close($process);
- if (preg_match('{--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n}', $info, $matches)) {
+ if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
return $matches[2].'x'.$matches[1];
}
}

0 comments on commit 583d999

Please sign in to comment.