Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2eeb7bd

Browse filesBrowse files
committed
switched to use COLUMNS and LINES env vars to change terminal dimensions
1 parent a38bb97 commit 2eeb7bd
Copy full SHA for 2eeb7bd

File tree

6 files changed

+57
-84
lines changed
Filter options

6 files changed

+57
-84
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+10-20Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -675,26 +675,16 @@ public function renderException(\Exception $e, OutputInterface $output)
675675
}
676676
}
677677

678-
/**
679-
* Returns the current terminal.
680-
*
681-
* @return Terminal
682-
*/
683-
public function getTerminal()
684-
{
685-
return $this->terminal;
686-
}
687-
688678
/**
689679
* Tries to figure out the terminal width in which this application runs.
690680
*
691681
* @return int|null
692682
*
693-
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
683+
* @deprecated since version 3.2, to be removed in 4.0. Create a Terminal instance instead.
694684
*/
695685
protected function getTerminalWidth()
696686
{
697-
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
687+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Create a Terminal instance instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
698688

699689
return $this->terminal->getWidth();
700690
}
@@ -704,11 +694,11 @@ protected function getTerminalWidth()
704694
*
705695
* @return int|null
706696
*
707-
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
697+
* @deprecated since version 3.2, to be removed in 4.0. Create a Terminal instance instead.
708698
*/
709699
protected function getTerminalHeight()
710700
{
711-
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
701+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Create a Terminal instance instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
712702

713703
return $this->terminal->getHeight();
714704
}
@@ -718,11 +708,11 @@ protected function getTerminalHeight()
718708
*
719709
* @return array Array containing width and height
720710
*
721-
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
711+
* @deprecated since version 3.2, to be removed in 4.0. Create a Terminal instance instead.
722712
*/
723713
public function getTerminalDimensions()
724714
{
725-
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
715+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Create a Terminal instance instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
726716

727717
return array($this->terminal->getWidth(), $this->terminal->getHeight());
728718
}
@@ -737,14 +727,14 @@ public function getTerminalDimensions()
737727
*
738728
* @return Application The current application
739729
*
740-
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
730+
* @deprecated since version 3.2, to be removed in 4.0. Set the COLUMNS and LINES env vars instead.
741731
*/
742732
public function setTerminalDimensions($width, $height)
743733
{
744-
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
734+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Set the COLUMNS and LINES env vars instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
745735

746-
$this->terminal->setWidth($width);
747-
$this->terminal->setHeight($height);
736+
putenv('COLUMNS='.$width);
737+
putenv('LINES='.$height);
748738

749739
return $this;
750740
}

‎src/Symfony/Component/Console/Helper/ProgressBar.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/ProgressBar.php
-14Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -426,20 +426,6 @@ public function clear()
426426
$this->overwrite('');
427427
}
428428

429-
/**
430-
* Gets the terminal.
431-
*
432-
* Can be useful to force terminal dimensions for functional tests.
433-
*
434-
* @return Terminal
435-
*
436-
* @internal
437-
*/
438-
public function getTerminal()
439-
{
440-
return $this->terminal;
441-
}
442-
443429
/**
444430
* Sets the progress bar format.
445431
*

‎src/Symfony/Component/Console/Terminal.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Terminal.php
+12-29Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ public function getWidth()
3030
return $this->width;
3131
}
3232

33-
/**
34-
* Sets the terminal width.
35-
*
36-
* @param int $width
37-
*/
38-
public function setWidth($width)
39-
{
40-
$this->width = $width;
41-
}
42-
4333
/**
4434
* Gets the terminal height.
4535
*
@@ -54,28 +44,21 @@ public function getHeight()
5444
return $this->height;
5545
}
5646

57-
/**
58-
* Sets the terminal height.
59-
*
60-
* @param int $height
61-
*/
62-
public function setHeight($height)
63-
{
64-
$this->height = $height;
65-
}
66-
6747
private function initDimensions()
6848
{
6949
if (null !== $this->width && null !== $this->height) {
7050
return;
7151
}
7252

53+
$this->width = (int) trim(getenv('COLUMNS'));
54+
$this->height = (int) trim(getenv('LINES'));
7355
$width = $height = null;
7456
if ($this->isWindowsEnvironment()) {
75-
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
57+
if (preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim(getenv('ANSICON')), $matches)) {
7658
// extract [w, H] from "wxh (WxH)"
77-
$width = (int) $matches[1];
78-
$height = (int) $matches[2];
59+
// or [w, h] from "wxh"
60+
$width = $matches[1];
61+
$height = isset($matches[4]) ? $matches[4] : $matches[2];
7962
} elseif (null != $dimensions = $this->getConsoleMode()) {
8063
// extract [w, h] from "wxh"
8164
$width = $dimensions[0];
@@ -84,21 +67,21 @@ private function initDimensions()
8467
} elseif ($sttyString = $this->getSttyColumns()) {
8568
if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
8669
// extract [w, h] from "rows h; columns w;"
87-
$width = (int) $matches[1];
88-
$height = (int) $matches[2];
70+
$width = $matches[1];
71+
$height = $matches[2];
8972
} elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
9073
// extract [w, h] from "; h rows; w columns"
91-
$width = (int) $matches[2];
92-
$heighth = (int) $matches[1];
74+
$width = $matches[2];
75+
$heighth = $matches[1];
9376
}
9477
}
9578

9679
if (null === $this->width) {
97-
$this->width = $width;
80+
$this->width = (int) $width;
9881
}
9982

10083
if (null === $this->height) {
101-
$this->height = $height;
84+
$this->height = (int) $height;
10285
}
10386
}
10487

‎src/Symfony/Component/Console/Tests/ApplicationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+9-12Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public function testSetCatchExceptions()
478478
{
479479
$application = new Application();
480480
$application->setAutoExit(false);
481-
$application->getTerminal()->setWidth(120);
481+
putenv('COLUMNS=120');
482482
$tester = new ApplicationTester($application);
483483

484484
$application->setCatchExceptions(true);
@@ -514,7 +514,7 @@ public function testRenderException()
514514
{
515515
$application = new Application();
516516
$application->setAutoExit(false);
517-
$application->getTerminal()->setWidth(120);
517+
putenv('COLUMNS=120');
518518
$tester = new ApplicationTester($application);
519519

520520
$tester->run(array('command' => 'foo'), array('decorated' => false, 'capture_stderr_separately' => true));
@@ -544,18 +544,19 @@ public function testRenderException()
544544

545545
$application = new Application();
546546
$application->setAutoExit(false);
547-
$application->getTerminal()->setWidth(32);
547+
putenv('COLUMNS=32');
548548
$tester = new ApplicationTester($application);
549549

550550
$tester->run(array('command' => 'foo'), array('decorated' => false, 'capture_stderr_separately' => true));
551551
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getErrorOutput(true), '->renderException() wraps messages when they are bigger than the terminal');
552+
putenv('COLUMNS=120');
552553
}
553554

554555
public function testRenderExceptionWithDoubleWidthCharacters()
555556
{
556557
$application = new Application();
557558
$application->setAutoExit(false);
558-
$application->getTerminal()->setWidth(120);
559+
putenv('COLUMNS=120');
559560
$application->register('foo')->setCode(function () {
560561
throw new \Exception('エラーメッセージ');
561562
});
@@ -569,13 +570,14 @@ public function testRenderExceptionWithDoubleWidthCharacters()
569570

570571
$application = new Application();
571572
$application->setAutoExit(false);
572-
$application->getTerminal()->setWidth(32);
573+
putenv('COLUMNS=32');
573574
$application->register('foo')->setCode(function () {
574575
throw new \Exception('コマンドの実行中にエラーが発生しました。');
575576
});
576577
$tester = new ApplicationTester($application);
577578
$tester->run(array('command' => 'foo'), array('decorated' => false, 'capture_stderr_separately' => true));
578579
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth2.txt', $tester->getErrorOutput(true), '->renderException() wraps messages when they are bigger than the terminal');
580+
putenv('COLUMNS=120');
579581
}
580582

581583
public function testRun()
@@ -1019,16 +1021,11 @@ public function testRunWithDispatcherAddingInputOptions()
10191021
public function testTerminalDimensions()
10201022
{
10211023
$application = new Application();
1024+
$application->setTerminalDimensions(120, 80);
10221025
$originalDimensions = $application->getTerminalDimensions();
10231026
$this->assertCount(2, $originalDimensions);
10241027

1025-
$width = 80;
1026-
if ($originalDimensions[0] == $width) {
1027-
$width = 100;
1028-
}
1029-
1030-
$application->setTerminalDimensions($width, 80);
1031-
$this->assertSame(array($width, 80), $application->getTerminalDimensions());
1028+
$this->assertSame(array(120, 80), $application->getTerminalDimensions());
10321029
}
10331030

10341031
protected function getDispatcher($skipCommand = false)

‎src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
+24-7Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,10 @@ public function testWithSmallScreen()
522522
$output = $this->getOutputStream();
523523

524524
$bar = new ProgressBar($output);
525-
$bar->getTerminal()->setWidth(12);
525+
putenv('COLUMNS=12');
526526
$bar->start();
527527
$bar->advance();
528+
putenv('COLUMNS=120');
528529

529530
rewind($output->getStream());
530531
$this->assertEquals(
@@ -577,6 +578,8 @@ public function testMultilineFormat()
577578

578579
public function testAnsiColorsAndEmojis()
579580
{
581+
putenv('COLUMNS=156');
582+
580583
$bar = new ProgressBar($output = $this->getOutputStream(), 15);
581584
ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
582585
static $i = 0;
@@ -592,23 +595,37 @@ public function testAnsiColorsAndEmojis()
592595

593596
$bar->setMessage('Starting the demo... fingers crossed', 'title');
594597
$bar->start();
595-
$bar->setMessage('Looks good to me...', 'title');
596-
$bar->advance(4);
597-
$bar->setMessage('Thanks, bye', 'title');
598-
$bar->finish();
599598

600599
rewind($output->getStream());
601600
$this->assertEquals(
602601
$this->generateOutput(
603602
" \033[44;37m Starting the demo... fingers crossed \033[0m\n".
604603
' 0/15 '.$progress.str_repeat($empty, 26)." 0%\n".
605604
" \xf0\x9f\x8f\x81 < 1 sec \033[44;37m 0 B \033[0m"
606-
).
605+
),
606+
stream_get_contents($output->getStream())
607+
);
608+
ftruncate($output->getStream(), 0);
609+
610+
$bar->setMessage('Looks good to me...', 'title');
611+
$bar->advance(4);
612+
613+
rewind($output->getStream());
614+
$this->assertEquals(
607615
$this->generateOutput(
608616
" \033[44;37m Looks good to me... \033[0m\n".
609617
' 4/15 '.str_repeat($done, 7).$progress.str_repeat($empty, 19)." 26%\n".
610618
" \xf0\x9f\x8f\x81 < 1 sec \033[41;37m 97 KiB \033[0m"
611-
).
619+
),
620+
stream_get_contents($output->getStream())
621+
);
622+
ftruncate($output->getStream(), 0);
623+
624+
$bar->setMessage('Thanks, bye', 'title');
625+
$bar->finish();
626+
627+
rewind($output->getStream());
628+
$this->assertEquals(
612629
$this->generateOutput(
613630
" \033[44;37m Thanks, bye \033[0m\n".
614631
' 15/15 '.str_repeat($done, 28)." 100%\n".

‎src/Symfony/Component/Console/Tests/TerminalTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/TerminalTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class TerminalTest extends \PHPUnit_Framework_TestCase
1717
{
1818
public function test()
1919
{
20+
putenv('COLUMNS=100');
21+
putenv('LINES=50');
2022
$terminal = new Terminal();
21-
$terminal->setWidth(100);
22-
$terminal->setHeight(50);
2323
$this->assertSame(100, $terminal->getWidth());
2424
$this->assertSame(50, $terminal->getHeight());
2525
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.