Skip to content

Commit

Permalink
bug #19253 [Console] Fix block() padding formatting after #19189 (cha…
Browse files Browse the repository at this point in the history
…lasr)

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
  • Loading branch information
fabpot committed Jun 30, 2016
2 parents 6471842 + dc130be commit c7d569a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,16 @@ private function createBlock($messages, $type = null, $style = null, $prefix = '
}
}

$firstLineIndex = 0;
if ($padding && $this->isDecorated()) {
$firstLineIndex = 1;
array_unshift($lines, '');
$lines[] = '';
}

foreach ($lines as $i => &$line) {
if (null !== $type) {
$line = 0 === $i ? $type.$line : $lineIndentation.$line;
$line = $firstLineIndex === $i ? $type.$line : $lineIndentation.$line;
}

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

if ($padding && $this->isDecorated()) {
array_unshift($lines, '');
$lines[] = '';
}

return $lines;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;

// ensure that block() output is properly formatted (even padding lines)
return function (InputInterface $input, OutputInterface $output) {
$output->setDecorated(true);
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->success(
'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',
'TEST'
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

 
 [OK] 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 
 

0 comments on commit c7d569a

Please sign in to comment.