8000 merged branch jcowgill/console-windows-fix (PR #4594) · symfony/symfony@086ff48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 086ff48

Browse files
committed
merged branch jcowgill/console-windows-fix (PR #4594)
Commits ------- bb87a71 [Console] Use 'mode' command to detect terminal size on Windows Discussion ---------- [Console] Use 'mode' command to detect terminal size on Windows This PR uses the windows 'mode' command to get the terminal height and width on windows. I've left in the ANSICON stuff but I'm not sure if that's needed after this. --------------------------------------------------------------------------- by travisbot at 2012-06-16T10:37:25Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1634120) (merged a490b6ec into f881d28). --------------------------------------------------------------------------- by fabpot at 2012-06-16T16:17:24Z ping @Seldaek --------------------------------------------------------------------------- by Seldaek at 2012-06-16T17:03:22Z It's a good addition, but you should still use ANSICON first if it's available. mode returns the buffer size and not the window size, which means the lines are not the real terminal height, but the buffer setting. ANSICON has both informations and hence allows you to be more correct. For columns/width both offer equally good information since the buffer size is not bigger than the window. --------------------------------------------------------------------------- by fabpot at 2012-06-17T10:41:21Z Can you squash your commits before I merge? Thanks. --------------------------------------------------------------------------- by jcowgill at 2012-06-17T13:23:01Z Yes that's fine. --------------------------------------------------------------------------- by fabpot at 2012-06-18T12:04:43Z @jcowgill there are still 3 commits. --------------------------------------------------------------------------- by jcowgill at 2012-06-18T14:59:51Z Woops, it's done now
2 parents faccd25 + bb87a71 commit 086ff48

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,15 @@ public function renderException($e, $output)
834834
*/
835835
protected function getTerminalWidth()
836836
{
837-
if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) {
838-
return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
837+
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
838+
if ($ansicon = getenv('ANSICON')) {
839+
return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
840+
}
841+
842+
exec('mode CON', $execData);
843+
if (preg_match('{columns:\s*(\d+)}i', $execData[4], $matches)) {
844+
return $matches[1];
845+
}
839846
}
840847

841848
if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {
@@ -850,8 +857,15 @@ protected function getTerminalWidth()
850857
*/
851858
protected function getTerminalHeight()
852859
{
853-
if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) {
854-
return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
860+
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
861+
if ($ansicon = getenv('ANSICON')) {
862+
return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
863+
}
864+
865+
exec('mode CON', $execData);
866+
if (preg_match('{lines:\s*(\d+)}i', $execData[3], $matches)) {
867+
return $matches[1];
868+
}
855869
}
856870

857871
if (preg_match("{rows.(\d+);.columns.(\d+);}i", $this->getSttyColumns(), $match)) {

0 commit comments

Comments
 (0)
0