From 9a4fcecbcccf4b55f4c28e1c71e3cd83d7be99b8 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 26 Jul 2021 15:29:22 +0200 Subject: [PATCH 1/5] Fix return types for PHP 8.1 --- Helper/HelperSet.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Helper/HelperSet.php b/Helper/HelperSet.php index d9d73f25f..9aa1e67ba 100644 --- a/Helper/HelperSet.php +++ b/Helper/HelperSet.php @@ -98,8 +98,9 @@ public function getCommand() } /** - * @return Helper[] + * @return \Traversable */ + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayIterator($this->helpers); From 37e6cca375ed4cca2a82c81487cd077520f6cab2 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 5 Aug 2021 01:50:27 +0200 Subject: [PATCH 2/5] Don't pass null to preg_replace() Signed-off-by: Alexander M. Turek --- Helper/Helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/Helper.php b/Helper/Helper.php index 881b4dc4f..a008166b9 100644 --- a/Helper/Helper.php +++ b/Helper/Helper.php @@ -170,7 +170,7 @@ public static function removeDecoration(OutputFormatterInterface $formatter, ?st // remove <...> formatting $string = $formatter->format($string ?? ''); // remove already formatted characters - $string = preg_replace("/\033\[[^m]*m/", '', $string); + $string = preg_replace("/\033\[[^m]*m/", '', $string ?? ''); $formatter->setDecorated($isDecorated); return $string; From 45daf168036763f04bf9b2f84190d16addceaa57 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 13 Aug 2021 17:54:02 +0200 Subject: [PATCH 3/5] Fix deprecation messages --- Helper/Helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Helper.php b/Helper/Helper.php index a008166b9..cfcbbd9a1 100644 --- a/Helper/Helper.php +++ b/Helper/Helper.php @@ -42,7 +42,7 @@ public function getHelperSet() /** * Returns the length of a string, using mb_strwidth if it is available. * - * @deprecated since 5.3 + * @deprecated since Symfony 5.3 * * @return int The length of the string */ @@ -154,7 +154,7 @@ public static function formatMemory(int $memory) } /** - * @deprecated since 5.3 + * @deprecated since Symfony 5.3 */ public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) { From 2be7b5c3d5f3833f7ba09544c0b8440314b52bcf Mon Sep 17 00:00:00 2001 From: rtek Date: Sun, 22 Aug 2021 17:39:32 -0400 Subject: [PATCH 4/5] Fix ProgressBar to correctly clear multi-line formats --- Helper/ProgressBar.php | 6 ++++-- Tests/Helper/ProgressBarTest.php | 33 ++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index 91fba2b58..1c03a1d96 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -482,8 +482,10 @@ private function overwrite(string $message): void } $this->output->clear($lineCount); } else { - if ($this->formatLineCount > 0) { - $this->cursor->moveUp($this->formatLineCount); + for ($i = 0; $i < $this->formatLineCount; ++$i) { + $this->cursor->moveToColumn(1); + $this->cursor->clearLine(); + $this->cursor->moveUp(); } $this->cursor->moveToColumn(1); diff --git a/Tests/Helper/ProgressBarTest.php b/Tests/Helper/ProgressBarTest.php index e424a29df..ef5f06222 100644 --- a/Tests/Helper/ProgressBarTest.php +++ b/Tests/Helper/ProgressBarTest.php @@ -812,7 +812,7 @@ public function testMultilineFormat() $this->assertEquals( ">---------------------------\nfoobar". $this->generateOutput("=========>------------------\nfoobar"). - "\x1B[1A\x1B[1G\x1B[2K". + "\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K". $this->generateOutput("============================\nfoobar"), stream_get_contents($output->getStream()) ); @@ -983,7 +983,7 @@ protected function generateOutput($expected) { $count = substr_count($expected, "\n"); - return ($count ? sprintf("\x1B[%dA\x1B[1G\x1b[2K", $count) : "\x1B[1G\x1B[2K").$expected; + return ($count ? str_repeat("\x1B[1G\x1b[2K\x1B[1A", $count) : '')."\x1B[1G\x1B[2K".$expected; } public function testBarWidthWithMultilineFormat() @@ -1095,4 +1095,33 @@ public function testNoWriteWhenMessageIsSame() stream_get_contents($output->getStream()) ); } + + public function testMultiLineFormatIsFullyCleared() + { + $bar = new ProgressBar($output = $this->getOutputStream(), 3); + $bar->setFormat("%current%/%max%\n%message%\nFoo"); + + $bar->setMessage('1234567890'); + $bar->start(); + $bar->display(); + + $bar->setMessage('ABC'); + $bar->advance(); + $bar->display(); + + $bar->setMessage('A'); + $bar->advance(); + $bar->display(); + + $bar->finish(); + + rewind($output->getStream()); + $this->assertEquals( + "0/3\n1234567890\nFoo". + $this->generateOutput("1/3\nABC\nFoo"). + $this->generateOutput("2/3\nA\nFoo"). + $this->generateOutput("3/3\nA\nFoo"), + stream_get_contents($output->getStream()) + ); + } } From a3f7189a0665ee33b50e9e228c46f50f5acbed22 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 25 Aug 2021 21:27:26 +0200 Subject: [PATCH 5/5] Fix optional before mandatory parameters Signed-off-by: Alexander M. Turek --- Event/ConsoleEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Event/ConsoleEvent.php b/Event/ConsoleEvent.php index 5440da216..400eb5731 100644 --- a/Event/ConsoleEvent.php +++ b/Event/ConsoleEvent.php @@ -28,7 +28,7 @@ class ConsoleEvent extends Event private $input; private $output; - public function __construct(Command $command = null, InputInterface $input, OutputInterface $output) + public function __construct(?Command $command, InputInterface $input, OutputInterface $output) { $this->command = $command; $this->input = $input;