From bb87a71226f1f194b3ff1c97e88ded544154c040 Mon Sep 17 00:00:00 2001 From: James Cowgill Date: Sat, 16 Jun 2012 09:57:49 +0100 Subject: [PATCH] [Console] Use 'mode' command to detect terminal size on Windows --- src/Symfony/Component/Console/Application.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index d1c2e3908926..0c49df86ce7d 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -834,8 +834,15 @@ public function renderException($e, $output) */ protected function getTerminalWidth() { - if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) { - return preg_replace('{^(\d+)x.*$}', '$1', $ansicon); + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + if ($ansicon = getenv('ANSICON')) { + return preg_replace('{^(\d+)x.*$}', '$1', $ansicon); + } + + exec('mode CON', $execData); + if (preg_match('{columns:\s*(\d+)}i', $execData[4], $matches)) { + return $matches[1]; + } } if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) { @@ -850,8 +857,15 @@ protected function getTerminalWidth() */ protected function getTerminalHeight() { - if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) { - return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon)); + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + if ($ansicon = getenv('ANSICON')) { + return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon)); + } + + exec('mode CON', $execData); + if (preg_match('{lines:\s*(\d+)}i', $execData[3], $matches)) { + return $matches[1]; + } } if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {