Skip to content

Commit

Permalink
bug #22377 [Console] Allow terminal dimensions to be set to 0 (unboun…
Browse files Browse the repository at this point in the history
…ded) (duncan3dc)

This PR was merged into the 3.2 branch.

Discussion
----------

[Console] Allow terminal dimensions to be set to 0 (unbounded)

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21513
| License       | MIT

A previous PR (#20328) changed the behavior of terminals with undefined widths from unbounded to 80 characters. And due to the way the existing code worked it become impossible to set a terminal to be unbounded again. This PR provides a way to restore the previous behavior:
```php
putenv('COLUMNS=0');
```

Commits
-------

4c1b001 Allow terminal dimensions to be set to 0 (unbounded)
  • Loading branch information
fabpot committed Apr 11, 2017
2 parents d41a3a5 + 4c1b001 commit ed1e8fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Symfony/Component/Console/Terminal.php
Expand Up @@ -23,8 +23,9 @@ class Terminal
*/
public function getWidth()
{
if ($width = trim(getenv('COLUMNS'))) {
return (int) $width;
$width = getenv('COLUMNS');
if (false !== $width) {
return (int) trim($width);
}

if (null === self::$width) {
Expand All @@ -41,8 +42,9 @@ public function getWidth()
*/
public function getHeight()
{
if ($height = trim(getenv('LINES'))) {
return (int) $height;
$height = getenv('LINES');
if (false !== $height) {
return (int) trim($height);
}

if (null === self::$height) {
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Console/Tests/TerminalTest.php
Expand Up @@ -30,4 +30,15 @@ public function test()
$this->assertSame(120, $terminal->getWidth());
$this->assertSame(60, $terminal->getHeight());
}

public function test_zero_values()
{
putenv('COLUMNS=0');
putenv('LINES=0');

$terminal = new Terminal();

$this->assertSame(0, $terminal->getWidth());
$this->assertSame(0, $terminal->getHeight());
}
}

0 comments on commit ed1e8fb

Please sign in to comment.