Skip to content

Navigation Menu

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 9be3790

Browse filesBrowse files
committed
f
1 parent c93d5e0 commit 9be3790
Copy full SHA for 9be3790

File tree

2 files changed

+32
-8
lines changed
Filter options

2 files changed

+32
-8
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/ProgressBar.php
+7-8
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,6 @@ private function setRealFormat(string $format): void
475475
*/
476476
private function overwrite(string $message): void
477477
{
478-
$newline = false;
479-
480-
if (str_ends_with($message, \PHP_EOL)) {
481-
$message = substr($message, 0, -\strlen(\PHP_EOL));
482-
$newline = true;
483-
}
484-
485478
if ($this->previousMessage === $message) {
486479
return;
487480
}
@@ -493,6 +486,12 @@ private function overwrite(string $message): void
493486
if ($this->output instanceof ConsoleSectionOutput) {
494487
$messageLines = explode("\n", $this->previousMessage);
495488
$lineCount = \count($messageLines);
489+
490+
// When the previous line was ending with a newline it is already clear by the section output, so we don't need to clear it again
491+
if (str_ends_with($this->previousMessage, \PHP_EOL)) {
492+
--$lineCount;
493+
}
494+
496495
foreach ($messageLines as $messageLine) {
497496
$messageLineLength = Helper::width(Helper::removeDecoration($this->output->getFormatter(), $messageLine));
498497
if ($messageLineLength > $this->terminal->getWidth()) {
@@ -519,7 +518,7 @@ private function overwrite(string $message): void
519518
$this->previousMessage = $originalMessage;
520519
$this->lastWriteTime = microtime(true);
521520

522-
$this->output->write($message, $newline);
521+
$this->output->write($message);
523522
++$this->writeCount;
524523
}
525524

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
+25
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,31 @@ public function testOverwriteWithSectionOutputAndEol()
441441
);
442442
}
443443

444+
public function testOverwriteWithSectionOutputAndEolWithEmptyMessage()
445+
{
446+
$sections = [];
447+
$stream = $this->getOutputStream(true);
448+
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
449+
450+
$bar = new ProgressBar($output, 50, 0);
451+
$bar->setFormat('[%bar%] %percent:3s%%' . PHP_EOL . '%message%');
452+
$bar->setMessage('Start');
453+
$bar->start();
454+
$bar->display();
455+
$bar->setMessage('');
456+
$bar->advance();
457+
$bar->setMessage('Doing something...');
458+
$bar->advance();
459+
460+
rewind($output->getStream());
461+
$this->assertEquals(escapeshellcmd(
462+
'[>---------------------------] 0%'.\PHP_EOL.'Start'.\PHP_EOL.
463+
"\x1b[2A\x1b[0J".'[>---------------------------] 2%'.\PHP_EOL .
464+
"\x1b[1A\x1b[0J".'[=>--------------------------] 4%'.\PHP_EOL. 'Doing something...' . \PHP_EOL),
465+
escapeshellcmd(stream_get_contents($output->getStream()))
466+
);
467+
}
468+
444469
public function testOverwriteWithAnsiSectionOutput()
445470
{
446471
// output has 43 visible characters plus 2 invisible ANSI characters

0 commit comments

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