8000 Merge branch '2.1' · symfony/symfony@583d999 · GitHub
[go: up one dir, main page]

Skip to content

Commit 583d999

Browse files
committed
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
2 parents af07008 + d786e09 commit 583d999

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"doctrine/data-fixtures": "1.0.*",
6060
"doctrine/dbal": ">=2.2,<2.4-dev",
6161
"doctrine/orm": ">=2.2.3,<2.4-dev",
62-
"monolog/monolog": "1.*",
62+
"monolog/monolog": ">=1.0,<1.3-dev",
6363
"propel/propel1": "dev-master"
6464
},
6565
"autoload": {

src/Symfony/Component/Console/Application.php

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ public function renderException($e, $output)
797797
$len = $strlen($title);
798798
$width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
799799
$lines = array();
800-
foreach (preg_split("{\r?\n}", $e->getMessage()) as $line) {
800+
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
801801
foreach (str_split($line, $width - 4) as $line) {
802802
$lines[] = sprintf(' %s ', $line);
803803
$len = max($strlen($line) + 4, $len);
@@ -859,43 +859,55 @@ public function renderException($e, $output)
859859
*
860860
* @return int|null
861861
*/
862-
public function getTerminalWidth()
862+
protected function getTerminalWidth()
863863
{
864-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
865-
if ($ansicon = getenv('ANSICON')) {
866-
return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
867-
}
868-
869-
if (preg_match('{^(\d+)x\d+$}i', $this->getConsoleMode(), $matches)) {
870-
return $matches[1];
871-
}
872-
}
864+
$dimensions = $this->getTerminalDimensions();
873865

874-
if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {
875-
return $match[2];
876-
}
866+
return $dimensions[0];
877867
}
878868

879869
/**
880870
* Tries to figure out the terminal height in which this application runs
881871
*
882872
* @return int|null
883873
*/
884-
public function getTerminalHeight()
874+
protected function getTerminalHeight()
875+
{
876+
$dimensions = $this->getTerminalDimensions();
877+
878+
return $dimensions[1];
879+
}
880+
881+
/**
882+
* Tries to figure out the terminal dimensions based on the current environment
883+
*
884+
* @return array Array containing width and height
885+
*/
886+
public function getTerminalDimensions()
885887
{
886888
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
887-
if ($ansicon = getenv('ANSICON')) {
888-
return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
889+
// extract [w, H] from "wxh (WxH)"
890+
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
891+
return array((int) $matches[1], (int) $matches[2]);
889892
}
890-
891-
if (preg_match('{^\d+x(\d+)$}i', $this->getConsoleMode(), $matches)) {
892-
return $matches[1];
893+
// extract [w, h] from "wxh"
894+
if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) {
895+
return array((int) $matches[1], (int) $matches[2]);
893896
}
894897
}
895898

896-
if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {
897-
return $match[1];
899+
if ($sttyString = $this->getSttyColumns()) {
900+
// extract [w, h] from "rows h; columns w;"
901+
if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
902+
return array((int) $matches[2], (int) $matches[1]);
903+
}
904+
// extract [w, h] from "; h rows; w columns"
905+
if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
906+
return array((int) $matches[2], (int) $matches[1]);
907+
}
898908
}
909+
910+
return array(null, null);
899911
}
900912

901913
/**
@@ -996,7 +1008,7 @@ private function getConsoleMode()
9961008
fclose($pipes[2]);
9971009
proc_close($process);
9981010

999-
if (preg_match('{--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n}', $info, $matches)) {
1011+
if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
10001012
return $matches[2].'x'.$matches[1];
10011013
}
10021014
}

0 commit comments

Comments
 (0)
0