diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index afea03640d..313ba3f50e 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -36,7 +36,6 @@ use Symfony\Component\Console\Event\ConsoleExceptionEvent; use Symfony\Component\Console\Event\ConsoleTerminateEvent; use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\Console\Exception\LogicException; -use Symfony\Component\Console\Terminal; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index e0dce47a49..305094c99e 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -413,9 +413,7 @@ class ProgressBar $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat()); } - $line = $this->buildLine(); - $line = $this->adjustLineWidthToTerminalWidth($line); - $this->overwrite($line); + $this->overwrite($this->buildLine()); } /** @@ -601,7 +599,8 @@ class ProgressBar */ private function buildLine() { - return preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) { + $regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i"; + $callback = function ($matches) { if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) { $text = call_user_func($formatter, $this, $this->output); } elseif (isset($this->messages[$matches[1]])) { @@ -615,25 +614,17 @@ class ProgressBar } return $text; - }, $this->format); - } + }; + $line = preg_replace_callback($regex, $callback, $this->format); - /** - * @param string $line - * - * @return bool - */ - private function adjustLineWidthToTerminalWidth($line) - { $lineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line); $terminalWidth = $this->terminal->getWidth(); - if ($lineLength > $terminalWidth) { - $newBarWidth = $this->barWidth - $lineLength + $terminalWidth; - $this->setBarWidth($newBarWidth); - - return $this->buildLine(); + if ($lineLength <= $terminalWidth) { + return $line; } - return $line; + $this->setBarWidth($this->barWidth - $lineLength + $terminalWidth); + + return preg_replace_callback($regex, $callback, $this->format); } } diff --git a/src/Symfony/Component/Console/Style/SymfonyStyle.php b/src/Symfony/Component/Console/Style/SymfonyStyle.php index 8c572833c5..c89ad1667f 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Console\Style; -use Symfony\Component\Console\Application; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\Helper; diff --git a/src/Symfony/Component/Console/Terminal.php b/src/Symfony/Component/Console/Terminal.php index 8aec95bf70..ef2d8e44b8 100644 --- a/src/Symfony/Component/Console/Terminal.php +++ b/src/Symfony/Component/Console/Terminal.php @@ -33,7 +33,7 @@ class Terminal /** * Sets the terminal width. * - * @param int + * @param int $width */ public function setWidth($width) { @@ -57,7 +57,7 @@ class Terminal /** * Sets the terminal height. * - * @param int + * @param int $height */ public function setHeight($height) { diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index d78221efb7..e0a7fa889a 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -14,7 +14,6 @@ namespace Symfony\Component\Console\Tests\Helper; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Output\StreamOutput; -use Symfony\Component\Console\Terminal; /** * @group time-sensitive