symfony/symfony — pull request #6581 by gigablah (2013-01-05 17:58:29+00:00)
Title: [2.1] [Console] Added getTerminalDimensions() with fix for osx/freebsd

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Fixes the following tickets: -
Todo: -
License of the code: MIT
Documentation PR: -

For non-windows systems, the Console component makes use of stty -a to grab the dimensions of the terminal when formatting exception output. The regex pattern assumes a string like the following:

speed 38400 baud; rows 25; columns 80; line = 0;

However on OSX (and FreeBSD) the pattern is different:

speed 38400 baud; 25 rows; 80 columns;

This patch adds a fix to match the correct pattern on darwin/freebsd systems, and consolidates the code in getTerminalWidth() and getTerminalHeight() into a general getTerminalDimensions() function. I've also taken the liberty of changing the curly brace regex delimiters to forward slashes for consistency with the rest of the codebase.