[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:
parent
b51de93e6c
commit
29c71a50f1
@ -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