[Console] Add clear() to ProgressHelper.

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.
This commit is contained in:
Martin Pärtel 2013-05-17 10:15:24 +03:00
parent b51de93e6c
commit 29c71a50f1
2 changed files with 26 additions and 0 deletions

View File

@ -289,6 +289,18 @@ class ProgressHelper extends Helper
$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.
*/

View File

@ -151,6 +151,20 @@ class ProgressHelperTest extends \PHPUnit_Framework_TestCase
$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()
{
return new StreamOutput(fopen('php://memory', 'r+', false));