10000 bug #19253 [Console] Fix block() padding formatting after #19189 (cha… · symfony/symfony@c7d569a · GitHub
[go: up one dir, main page]

Skip to content

Commit c7d569a

Browse files
committed
bug #19253 [Console] Fix block() padding formatting after #19189 (chalasr)
This PR was merged into the 2.8 branch. Discussion ---------- [Console] Fix block() padding formatting after #19189 | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19189 (comment) | License | MIT | Doc PR | reference to the documentation PR, if any This fixes the unformatted padding of `block()` output after #19189. Commits ------- dc130be [Console] Fix for block() padding formatting after #19189
2 parents 6471842 + dc130be commit c7d569a

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,16 @@ private function createBlock($messages, $type = null, $style = null, $prefix = '
410410
}
411411
}
412412

413+
$firstLineIndex = 0;
414+
if ($padding && $this->isDecorated()) {
415+
$firstLineIndex = 1;
416+
array_unshift($lines, '');
417+
$lines[] = '';
418+
}
419+
413420
foreach ($lines as $i => &$line) {
414421
if (null !== $type) {
415-
$line = 0 === $i ? $type.$line : $lineIndentation.$line;
422+
$line = $firstLineIndex === $i ? $type.$line : $lineIndentation.$line;
416423
}
417424

418425
$line = $prefix.$line;
@@ -423,11 +430,6 @@ private function createBlock($messages, $type = null, $style = null, $prefix = '
423430
}
424431
}
425432

426-
if ($padding && $this->isDecorated()) {
427-
array_unshift($lines, '');
428-
$lines[] = '';
429-
}
430-
431433
return $lines;
432434
}
433435
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
// ensure that block() output is properly formatted (even padding lines)
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output->setDecorated(true);
10+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
11+
$output->success(
12+
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum',
13+
'TEST'
14+
);
15+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
 
3+
 [OK] Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore 
4+
 magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
5+
 consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
6+
 Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum 
7+
 
8+

0 commit comments

Comments
 (0)
0