[Console] Added a way to set terminal dimensions
This commit is contained in:
parent
5cbfe302c2
commit
ce329815d5
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user