merged branch lyrixx/console-set-dimension (PR #8603)

This PR was squashed before being merged into the master branch (closes #8603).

Discussion
----------

[Console] Added a way to set terminal dimensions

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8595
| License       | MIT
| Doc PR        | n/

Commits
-------

ce32981 [Console] Added a way to set terminal dimensions
This commit is contained in:
Fabien Potencier 2013-08-09 08:00:31 +02:00
commit 11393def7e
3 changed files with 38 additions and 0 deletions

View File

@ -66,6 +66,7 @@ class Application
private $definition;
private $helperSet;
private $dispatcher;
private $terminalDimensions;
/**
* Constructor.
@ -829,6 +830,10 @@ class Application
*/
public function getTerminalDimensions()
{
if ($this->terminalDimensions) {
return $this->terminalDimensions;
}
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
// extract [w, H] from "wxh (WxH)"
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
@ -854,6 +859,23 @@ class Application
return array(null, null);
}
/**
* Sets terminal dimensions.
*
* Can be useful to force terminal dimensions for functional tests.
*
* @param integer $width The width
* @param integer $height The height
*
* @return Application The current application
*/
public function setTerminalDimensions($width, $height)
{
$this->terminalDimensions = array($width, $height);
return $this;
}
/**
* Configures the input and output instances based on the user arguments and options.
*

View File

@ -4,6 +4,7 @@ CHANGELOG
2.4.0
-----
* added a way to force terminal dimensions
* [BC BREAK] made descriptors use output instead of returning a string
2.3.0

View File

@ -792,6 +792,21 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertContains('before.foo.after.caught.', $tester->getDisplay());
}
public function testTerminalDimensions()
{
$application = new Application();
$originalDimensions = $application->getTerminalDimensions();
$this->assertCount(2, $originalDimensions);
$width = 80;
if ($originalDimensions[0] == $width) {
$width = 100;
}
$application->setTerminalDimensions($width, 80);
$this->assertSame(array($width, 80), $application->getTerminalDimensions());
}
protected function getDispatcher()
{
$dispatcher = new EventDispatcher;