Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a78fb18

Browse filesBrowse files
bug #40450 [Console] ProgressBar clears too many lines on update (danepowell)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Console] ProgressBar clears too many lines on update | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? |no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | License | MIT The ProgressBar incorrectly calculates line lengths when updating, including non-displayable characters such as ANSI colors. This causes it to clear too many lines if the terminal width is greater than the displayed line length but less than the line length including non-displayed characters. An example of this bug in action is https://github.com/acquia/cli/issues/467 Commits ------- 2aa3df0 [Console] ProgressBar clears too many lines on update
2 parents e21004d + 2aa3df0 commit a78fb18
Copy full SHA for a78fb18

File tree

Expand file treeCollapse file tree

2 files changed

+26
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-1
lines changed

‎src/Symfony/Component/Console/Helper/ProgressBar.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/ProgressBar.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private function overwrite(string $message): void
441441
if ($this->overwrite) {
442442
if (null !== $this->previousMessage) {
443443
if ($this->output instanceof ConsoleSectionOutput) {
444-
$lines = floor(Helper::strlen($message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
444+
$lines = floor(Helper::strlenWithoutDecoration($this->output->getFormatter(), $message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
445445
$this->output->clear($lines);
446446
} else {
447447
// Erase previous lines

‎src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,31 @@ public function testOverwriteWithSectionOutput()
343343
);
344344
}
345345

346+
public function testOverwriteWithAnsiSectionOutput()
347+
{
348+
// output has 43 visible characters plus 2 invisible ANSI characters
349+
putenv('COLUMNS=43');
350+
$sections = [];
351+
$stream = $this->getOutputStream(true);
352+
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
353+
354+
$bar = new ProgressBar($output, 50, 0);
355+
$bar->setFormat(" \033[44;37m%current%/%max%\033[0m [%bar%] %percent:3s%%");
356+
$bar->start();
357+
$bar->display();
358+
$bar->advance();
359+
$bar->advance();
360+
361+
rewind($output->getStream());
362+
$this->assertSame(
363+
" \033[44;37m 0/50\033[0m [>---------------------------] 0%".\PHP_EOL.
364+
"\x1b[1A\x1b[0J"." \033[44;37m 1/50\033[0m [>---------------------------] 2%".\PHP_EOL.
365+
"\x1b[1A\x1b[0J"." \033[44;37m 2/50\033[0m [=>--------------------------] 4%".\PHP_EOL,
366+
stream_get_contents($output->getStream())
367+
);
368+
putenv('COLUMNS=120');
369+
}
370+
346371
public function testOverwriteMultipleProgressBarsWithSectionOutputs()
347372
{
348373
$sections = [];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.