Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbf9b4d

Browse files
committed
Prevent ProgressBar redraw when message is same
1 parent 7432601 commit dbf9b4d

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ final class ProgressBar
4242
private $overwrite = true;
4343
private $terminal;
4444
private $firstRun = true;
45+
private $currentMessage = '';
4546

4647
private static $formatters;
4748
private static $formats;
@@ -464,6 +465,12 @@ private function setMaxSteps($max)
464465
*/
465466
private function overwrite($message)
466467
{
468+
if ($this->currentMessage === $message) {
469+
return;
470+
}
471+
472+
$this->currentMessage = $message;
473+
467474
if ($this->overwrite) {
468475
if (!$this->firstRun) {
469476
// Erase previous lines

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ public function testFormat()
185185
{
186186
$expected =
187187
' 0/10 [>---------------------------] 0%'.
188-
$this->generateOutput(' 10/10 [============================] 100%').
189188
$this->generateOutput(' 10/10 [============================] 100%')
190189
;
191190

@@ -294,7 +293,6 @@ public function testPercent()
294293
rewind($output->getStream());
295294
$this->assertEquals(
296295
' 0/50 [>---------------------------] 0%'.
297-
$this->generateOutput(' 0/50 [>---------------------------] 0%').
298296
$this->generateOutput(' 1/50 [>---------------------------] 2%').
299297
$this->generateOutput(' 2/50 [=>--------------------------] 4%'),
300298
stream_get_contents($output->getStream())
@@ -316,7 +314,6 @@ public function testOverwriteWithShorterLine()
316314
rewind($output->getStream());
317315
$this->assertEquals(
318316
' 0/50 [>---------------------------] 0%'.
319-
$this->generateOutput(' 0/50 [>---------------------------] 0%').
320317
$this->generateOutput(' 1/50 [>---------------------------] 2%').
321318
$this->generateOutput(' 2/50 [=>--------------------------]'),
322319
stream_get_contents($output->getStream())
@@ -350,7 +347,6 @@ public function testSetCurrentProgress()
350347
rewind($output->getStream());
351348
$this->assertEquals(
352349
' 0/50 [>---------------------------] 0%'.
353-
$this->generateOutput(' 0/50 [>---------------------------] 0%').
354350
$this->generateOutput(' 1/50 [>---------------------------] 2%').
355351
$this->generateOutput(' 15/50 [========>-------------------] 30%').
356352
$this->generateOutput(' 25/50 [==============>-------------] 50%'),
@@ -457,7 +453,6 @@ public function testPercentNotHundredBeforeComplete()
457453
rewind($output->getStream());
458454
$this->assertEquals(
459455
' 0/200 [>---------------------------] 0%'.
460-
$this->generateOutput(' 0/200 [>---------------------------] 0%').
461456
$this->generateOutput(' 199/200 [===========================>] 99%').
462457
$this->generateOutput(' 200/200 [============================] 100%'),
463458
stream_get_contents($output->getStream())
@@ -802,4 +797,19 @@ public function testBarWidthWithMultilineFormat()
802797
$this->assertEquals(5, $bar->getBarWidth(), stream_get_contents($output->getStream()));
803798
putenv('COLUMNS=120');
804799
}
800+
801+
public function testNoWriteWhenMessageIsSame(): void
802+
{
803+
$bar = new ProgressBar($output = $this->getOutputStream(), 2);
804+
$bar->start();
805+
$bar->advance();
806+
$bar->display();
807+
808+
rewind($output->getStream());
809+
$this->assertEquals(
810+
' 0/2 [>---------------------------] 0%'.
811+
$this->generateOutput(' 1/2 [==============>-------------] 50%'),
812+
stream_get_contents($output->getStream())
813+
);
814+
}
805815
}

0 commit comments

Comments
 (0)