10000 [Console] Fix line wrapping for decorated text in block output · symfony/symfony@760be88 · GitHub
[go: up one dir, main page]

Skip to content

Commit 760be88

Browse files
grasmashnicolas-grekas
authored andcommitted
[Console] Fix line wrapping for decorated text in block output
1 parent a78fb18 commit 760be88

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,12 @@ private function createBlock(iterable $messages, string $type = null, string $st
471471
$message = OutputFormatter::escape($message);
472472
}
473473

474-
$lines = array_merge($lines, explode(\PHP_EOL, wordwrap($message, $this->lineLength - $prefixLength - $indentLength, \PHP_EOL, true)));
474+
$decorationLength = Helper::strlen($message) - Helper::strlenWithoutDecoration($this->getFormatter(), $message);
475+
$messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength);
476+
$messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true));
477+
foreach ($messageLines as $messageLine) {
478+
$lines[] = $messageLine;
479+
}
475480

476481
if (\count($messages) > 1 && $key < \count($messages) - 1) {
477482
$lines[] = '';
@@ -491,7 +496,9 @@ private function createBlock(iterable $messages, string $type = null, string $st
491496
}
492497

493498
$line = $prefix.$line;
494-
$line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line));
499+
$decorationLength = Helper::strlen($line) - Helper::strlenWithoutDecoration($this->getFormatter(), $line);
500+
$messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength);
501+
$line .= str_repeat(' ', max($this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line), 0));
495502

496503
if ($style) {
497504
$line = sprintf('<%s>%s</>', $style, $line);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
 // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 
3-
 // dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
4-
 // commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 
5-
 // pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim
6-
 // id est laborum
2+
 // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore 
3+
 // magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
4+
 // consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 
5+
 // pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
6+
 // est laborum
77

0 commit comments

Comments
 (0)
0