8000 [Console] ProgressBar clears too many lines on update by danepowell · Pull Request #40450 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] ProgressBar clears too many lines on update #40450

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
Mar 16, 2021
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
[Console] ProgressBar clears too many lines on update
  • Loading branch information
danepowell authored and nicolas-grekas committed Mar 16, 2021
commit 2aa3df0c74a79db531dcccaa577df301481b33b9
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private function overwrite(string $message): void
if ($this->overwrite) {
if (null !== $this->previousMessage) {
if ($this->output instanceof ConsoleSectionOutput) {
$lines = floor(Helper::strlen($message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
$lines = floor(Helper::strlenWithoutDecoration($this->output->getFormatter(), $message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
$this->output->clear($lines);
} else {
// Erase previous lines
Expand Down
25 changes: 25 additions & 0 deletions src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,31 @@ public function testOverwriteWithSectionOutput()
);
}

public function testOverwriteWithAnsiSectionOutput()
{
// output has 43 visible characters plus 2 invisible ANSI characters
putenv('COLUMNS=43');
$sections = [];
$stream = $this->getOutputStream(true);
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());

$bar = new ProgressBar($output, 50, 0);
$bar->setFormat(" \033[44;37m%current%/%max%\033[0m [%bar%] %percent:3s%%");
$bar->start();
$bar->display();
$bar->advance();
$bar->advance();

rewind($output->getStream());
$this->assertSame(
" \033[44;37m 0/50\033[0m [>---------------------------] 0%".\PHP_EOL.
"\x1b[1A\x1b[0J"." \033[44;37m 1/50\033[0m [>---------------------------] 2%".\PHP_EOL.
"\x1b[1A\x1b[0J"." \033[44;37m 2/50\033[0m [=>--------------------------] 4%".\PHP_EOL,
stream_get_contents($output->getStream())
);
putenv('COLUMNS=120');
}

public function testOverwriteMultipleProgressBarsWithSectionOutputs()
{
$sections = [];
Expand Down
0