merged branch mpartel/progresshelper-clear (PR #8074)
This PR was merged into the master branch.
Discussion
----------
[Console] Add clear() to ProgressHelper.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR | symfony/symfony-docs#2642
One may want to print something else while the progress bar is running.
The output will be messy if the progress bar is not removed first.
One may also want to remove the progress bar after the work is complete.
Commits
-------
29c71a5
[Console] Add clear() to ProgressHelper.
This commit is contained in:
commit
d8941c19c8
@ -289,6 +289,18 @@ class ProgressHelper extends Helper
|
|||||||
$this->overwrite($this->output, $message);
|
$this->overwrite($this->output, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the progress bar from the current line.
|
||||||
|
*
|
||||||
|
* This is useful if you wish to write some output
|
||||||
|
* while a progress bar is running.
|
||||||
|
* Call display() to show the progress bar again.
|
||||||
|
*/
|
||||||
|
public function clear()
|
||||||
|
{
|
||||||
|
$this->overwrite($this->output, '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finishes the progress output.
|
* Finishes the progress output.
|
||||||
*/
|
*/
|
||||||
|
@ -151,6 +151,20 @@ class ProgressHelperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($this->generateOutput(' 3 [■■■>------------------------]'), stream_get_contents($output->getStream()));
|
$this->assertEquals($this->generateOutput(' 3 [■■■>------------------------]'), stream_get_contents($output->getStream()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testClear()
|
||||||
|
{
|
||||||
|
$progress = new ProgressHelper();
|
||||||
|
$progress->start($output = $this->getOutputStream(), 50);
|
||||||
|
$progress->setCurrent(25);
|
||||||
|
$progress->clear();
|
||||||
|
|
||||||
|
rewind($output->getStream());
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->generateOutput(' 25/50 [==============>-------------] 50%') . $this->generateOutput(''),
|
||||||
|
stream_get_contents($output->getStream())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getOutputStream()
|
protected function getOutputStream()
|
||||||
{
|
{
|
||||||
return new StreamOutput(fopen('php://memory', 'r+', false));
|
return new StreamOutput(fopen('php://memory', 'r+', false));
|
||||||
|
Reference in New Issue
Block a user