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 4fe2c53

Browse filesBrowse files
committed
fix(console): fix section output when multiples section with max height
1 parent 6d11c7a commit 4fe2c53
Copy full SHA for 4fe2c53

File tree

2 files changed

+37
-3
lines changed
Filter options

2 files changed

+37
-3
lines changed

‎src/Symfony/Component/Console/Output/ConsoleSectionOutput.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Output/ConsoleSectionOutput.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function __construct($stream, array &$sections, int $verbosity, bool $dec
4848
public function setMaxHeight(int $maxHeight): void
4949
{
5050
// when changing max height, clear output of current section and redraw again with the new height
51-
$existingContent = $this->popStreamContentUntilCurrentSection($this->maxHeight ? min($this->maxHeight, $this->lines) : $this->lines);
52-
51+
$previousMaxHeight = $this->maxHeight;
5352
$this->maxHeight = $maxHeight;
53+
$existingContent = $this->popStreamContentUntilCurrentSection($previousMaxHeight ? min($previousMaxHeight, $this->lines) : $this->lines);
5454

5555
parent::doWrite($this->getVisibleContent(), false);
5656
parent::doWrite($existingContent, false);
@@ -213,7 +213,7 @@ private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFr
213213
break;
214214
}
215215

216-
$numberOfLinesToClear += $section->lines;
216+
$numberOfLinesToClear += $section->maxHeight ? min($section->lines, $section->maxHeight): $section->lines;
217217
if ('' !== $sectionContent = $section->getVisibleContent()) {
218218
if (!str_ends_with($sectionContent, \PHP_EOL)) {
219219
$sectionContent .= \PHP_EOL;

‎src/Symfony/Component/Console/Tests/Output/ConsoleSectionOutputTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Output/ConsoleSectionOutputTest.php
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,40 @@ public function testMaxHeight()
133133
$this->assertEquals($expected, stream_get_contents($output->getStream()));
134134
}
135135

136+
public function testMaxHeightMultipleSections()
137+
{
138+
$expected = '';
139+
$sections = [];
140+
141+
$firstSection = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
142+
$firstSection->setMaxHeight(3);
143+
144+
$secondSection = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
145+
$secondSection->setMaxHeight(3);
146+
147+
// fill the first section
148+
$firstSection->writeln(['One', 'Two', 'Three']);
149+
$expected .= 'One'.\PHP_EOL.'Two'.\PHP_EOL.'Three'.\PHP_EOL;
150+
151+
// fill the second section
152+
$secondSection->writeln(['One', 'Two', 'Three']);
153+
$expected .= 'One'.\PHP_EOL.'Two'.\PHP_EOL.'Three'.\PHP_EOL;
154+
155+
// cause overflow of second section (redraw whole section, without first line)
156+
$secondSection->writeln('Four');
157+
$expected .= "\x1b[3A\x1b[0J";
158+
$expected .= 'Two'.\PHP_EOL.'Three'.\PHP_EOL.'Four'.\PHP_EOL;
159+
160+
// cause overflow of first section (redraw whole section, without first line)
161+
$firstSection->writeln("Four\nFive\nSix");
162+
$expected .= "\x1b[6A\x1b[0J";
163+
$expected .= 'Four'.\PHP_EOL.'Five'.\PHP_EOL.'Six'.\PHP_EOL;
164+
$expected .= 'Two'.\PHP_EOL.'Three'.\PHP_EOL.'Four'.\PHP_EOL;
165+
166+
rewind($this->stream);
167+
$this->assertEquals(escapeshellcmd($expected), escapeshellcmd(stream_get_contents($this->stream)));
168+
}
169+
136170
public function testMaxHeightWithoutNewLine()
137171
{
138172
$expected = '';

0 commit comments

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