8000 [Console] fixed progress bar jumping for windows & unix env · Pull Request #6266 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] fixed progress bar jumping for windows & unix env #6266

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 2 commits into from Dec 11, 2012
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: 8 additions & 11 deletions src/Symfony/Component/Console/Helper/ProgressHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ProgressHelper extends Helper
private $format = null;
private $redrawFreq = 1;

private $lastMessagesLength;
private $barCharOriginal;

/**
Expand Down Expand Up @@ -380,21 +381,17 @@ private function humaneTime($secs)
*
* @param OutputInterface $output An Output instance
* @param string|array $messages The message as an array of lines or a single string
* @param Boolean $newline Whether to add a newline or not
* @param integer $size The size of line
*/
private function overwrite(OutputInterface $output, $messages, $newline = false, $size = 80)
private function overwrite(OutputInterface $output, $messages)
{
$output->write(str_repeat("\x08", $size));
$output->write("\x0D"); // carriage return
if($this->lastMessagesLength!==null){
$output->write(str_repeat("\x20", $this->lastMessagesLength)); //clear the line with the length of the last message
$output->write("\x0D"); // carriage return
}
$output->write($messages);
$output->write(str_repeat(' ', $size - strlen($messages)));

// clean up the end line
$output->write(str_repeat("\x08", $size - strlen($messages)));

if ($newline) {
$output->writeln('');
}
$this->lastMessagesLength=strlen($messages);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,18 @@ protected function getOutputStream()
return new StreamOutput(fopen('php://memory', 'r+', false));
}

protected $lastMessagesLength;

protected function generateOutput($expected)
{
return str_repeat("\x08", 80).$expected.str_repeat(' ', 80 - strlen($expected)).str_repeat("\x08", 80 - strlen($expected));
$expectedout = $expected;

if($this->lastMessagesLength!==null){
$expectedout=str_repeat("\x20", $this->lastMessagesLength)."\x0D".$expected;
}

$this->lastMessagesLength=strlen($expected);

return "\x0D".$expectedout;
}
}
0