Skip to content

[Console] simplified code #20372

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
Oct 31, 2016
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
19 changes: 1 addition & 18 deletions src/Symfony/Component/Console/Helper/ProgressIndicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class ProgressIndicator
private $indicatorCurrent;
private $indicatorChangeInterval;
private $indicatorUpdateTime;
private $lastMessagesLength;
private $started = false;

private static $formatters;
Expand Down Expand Up @@ -125,7 +124,6 @@ public function start($message)

$this->message = $message;
$this->started = true;
$this->lastMessagesLength = 0;
$this->startTime = time();
$this->indicatorUpdateTime = $this->getCurrentTimeInMilliseconds() + $this->indicatorChangeInterval;
$this->indicatorCurrent = 0;
Expand Down Expand Up @@ -262,27 +260,12 @@ private function determineBestFormat()
*/
private function overwrite($message)
{
// append whitespace to match the line's length
if (null !== $this->lastMessagesLength) {
if ($this->lastMessagesLength > Helper::strlenWithoutDecoration($this->output->getFormatter(), $message)) {
$message = str_pad($message, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT);
}
}

if ($this->output->isDecorated()) {
$this->output->write("\x0D");
$this->output->write("\x0D\x1B[2K");
$this->output->write($message);
} else {
$this->output->writeln($message);
}

$this->lastMessagesLength = 0;

$len = Helper::strlenWithoutDecoration($this->output->getFormatter(), $message);

if ($len > $this->lastMessagesLength) {
$this->lastMessagesLength = $len;
}
}

private function getCurrentTimeInMilliseconds()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function testDefaultIndicator()
$this->generateOutput(' \\ Starting...').
$this->generateOutput(' \\ Advancing...').
$this->generateOutput(' | Advancing...').
$this->generateOutput(' | Done... ').
$this->generateOutput(' | Done...').
PHP_EOL.
$this->generateOutput(' - Starting Again...').
$this->generateOutput(' \\ Starting Again...').
$this->generateOutput(' \\ Done Again... ').
$this->generateOutput(' \\ Done Again...').
PHP_EOL,
stream_get_contents($output->getStream())
);
Expand All @@ -70,8 +70,8 @@ public function testNonDecoratedOutput()

$this->assertEquals(
' Starting...'.PHP_EOL.
' Midway... '.PHP_EOL.
' Done... '.PHP_EOL.PHP_EOL,
' Midway...'.PHP_EOL.
' Done...'.PHP_EOL.PHP_EOL,
stream_get_contents($output->getStream())
);
}
Expand Down Expand Up @@ -177,6 +177,6 @@ protected function generateOutput($expected)
{
$count = substr_count($expected, "\n");

return "\x0D".($count ? sprintf("\033[%dA", $count) : '').$expected;
return "\x0D\x1B[2K".($count ? sprintf("\033[%dA", $count) : '').$expected;
}
}