Skip to content

[Console] hide output of ProgressHelper when isDecorated is false #9846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Symfony/Component/Console/Helper/ProgressHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -185,7 +186,9 @@ public function start(OutputInterface $output, $max = null)
$this->startTime = time();
$this->current = 0;
$this->max = (int) $max;
$this->output = $output;

// Disabling output when it does not support ANSI codes as it would result in a broken display anyway.
$this->output = $output->isDecorated() ? $output : new NullOutput();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a comment here to explained why we are doing that.

$this->lastMessagesLength = 0;
$this->barCharOriginal = '';

Expand Down
14 changes: 12 additions & 2 deletions src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,19 @@ public function testPercentNotHundredBeforeComplete()
$this->assertEquals($this->generateOutput(' 0/200 [>---------------------------] 0%').$this->generateOutput(' 199/200 [===========================>] 99%').$this->generateOutput(' 200/200 [============================] 100%'), stream_get_contents($output->getStream()));
}

protected function getOutputStream()
public function testNonDecoratedOutput()
{
return new StreamOutput(fopen('php://memory', 'r+', false));
$progress = new ProgressHelper();
$progress->start($output = $this->getOutputStream(false));
$progress->advance();

rewind($output->getStream());
$this->assertEquals('', stream_get_contents($output->getStream()));
}

protected function getOutputStream($decorated = true)
{
return new StreamOutput(fopen('php://memory', 'r+', false), StreamOutput::VERBOSITY_NORMAL, $decorated);
}

protected $lastMessagesLength;
Expand Down