Skip to content

Commit

Permalink
[Console] Use 'mode' command to detect terminal size on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jcowgill committed Jun 18, 2012
1 parent f881d28 commit bb87a71
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down

0 comments on commit bb87a71

Please sign in to comment.