Skip to content

Commit bf7a5c5

Browse files
committed
fixed logic
1 parent a589635 commit bf7a5c5

File tree

5 files changed

+12
-24
lines changed

5 files changed

+12
-24
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
3737
use Symfony\Component\Console\Exception\CommandNotFoundException;
3838
use Symfony\Component\Console\Exception\LogicException;
39-
use Symfony\Component\Console\Terminal;
4039
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4140

4241
/**

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,7 @@ public function display()
413413
$this->setRealFormat($this->internalFormat ?: $this->determineBestFormat());
414414
}
415415

416-
$line = $this->buildLine();
417-
$line = $this->adjustLineWidthToTerminalWidth($line);
418-
$this->overwrite($line);
416+
$this->overwrite($this->buildLine());
419417
}
420418

421419
/**
@@ -601,7 +599,8 @@ private static function initFormats()
601599
*/
602600
private function buildLine()
603601
{
604-
return preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) {
602+
$regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
603+
$callback = function ($matches) {
605604
if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) {
606605
$text = call_user_func($formatter, $this, $this->output);
607606
} elseif (isset($this->messages[$matches[1]])) {
@@ -615,25 +614,17 @@ private function buildLine()
615614
}
616615

617616
return $text;
618-
}, $this->format);
619-
}
617+
};
618+
$line = preg_replace_callback($regex, $callback, $this->format);
620619

621-
/**
622-
* @param string $line
623-
*
624-
* @return bool
625-
*/
626-
private function adjustLineWidthToTerminalWidth($line)
627-
{
628620
$lineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line);
629621
$terminalWidth = $this->terminal->getWidth();
630-
if ($lineLength > $terminalWidth) {
631-
$newBarWidth = $this->barWidth - $lineLength + $terminalWidth;
632-
$this->setBarWidth($newBarWidth);
633-
634-
return $this->buildLine();
622+
if ($lineLength <= $terminalWidth) {
623+
return $line;
635624
}
636625

637-
return $line;
626+
$this->setBarWidth($this->barWidth - $lineLength + $terminalWidth);
627+
628+
return preg_replace_callback($regex, $callback, $this->format);
638629
}
639630
}

src/Symfony/Component/Console/Style/SymfonyStyle.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Console\Style;
1313

14-
use Symfony\Component\Console\Application;
1514
use Symfony\Component\Console\Exception\RuntimeException;
1615
use Symfony\Component\Console\Formatter\OutputFormatter;
1716
use Symfony\Component\Console\Helper\Helper;

src/Symfony/Component/Console/Terminal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getWidth()
3333
/**
3434
* Sets the terminal width.
3535
*
36-
* @param int
36+
* @param int $width
3737
*/
3838
public function setWidth($width)
3939
{
@@ -57,7 +57,7 @@ public function getHeight()
5757
/**
5858
* Sets the terminal height.
5959
*
60-
* @param int
60+
* @param int $height
6161
*/
6262
public function setHeight($height)
6363
{

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Console\Helper\ProgressBar;
1515
use Symfony\Component\Console\Helper\Helper;
1616
use Symfony\Component\Console\Output\StreamOutput;
17-
use Symfony\Component\Console\Terminal;
1817

1918
/**
2019
* @group time-sensitive

0 commit comments

Comments
 (0)