Skip to content

Commit

Permalink
bug #18889 [Console] SymfonyStyle: Fix alignment/prefixing of multi-l…
Browse files Browse the repository at this point in the history
…ine comments (chalasr)

This PR was merged into the 2.8 branch.

Discussion
----------

[Console] SymfonyStyle: Fix alignment/prefixing of multi-line comments

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Pointed in #18564 (comment).

Very-long-line comment:
```php
SymfonyStyle::comment('Lorem ipsum ...');
```

Before:
![](http://image.prntscr.com/image/9190081d7fd740a89d17a7247dbbb244.png)

After:
![](http://image.prntscr.com/image/109c8c19c1574172bc22199ac90b6dd6.png)

Multi-line comment:
```php
SymfonyStyle::comment(['Lorem ipsum...', 'Lorem ipsum...']);
```

Before:
![](http://image.prntscr.com/image/24228f7e89e647b3a5d66fd83c7216cd.png)

After:
![](http://image.prntscr.com/image/fe9320369fad45acab92564f0e5de344.png)

Commits
-------

1c94fea [Console] SymfonyStyle: Fix alignment/prefixing of multi-line comments
  • Loading branch information
fabpot committed May 30, 2016
2 parents 56b5f41 + 1c94fea commit dfc0c81
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
Expand Up @@ -339,7 +339,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
*/
protected function describeContainerAlias(Alias $alias, array $options = array())
{
$options['output']->comment(sprintf("This service is an alias for the service <info>%s</info>\n", (string) $alias));
$options['output']->comment(sprintf('This service is an alias for the service <info>%s</info>', (string) $alias));
}

/**
Expand Down
@@ -1 +1,3 @@
// This service is an alias for the service service_1

// This service is an alias for the service service_1

@@ -1 +1,3 @@
// This service is an alias for the service service_2

// This service is an alias for the service service_2

12 changes: 7 additions & 5 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -170,16 +170,18 @@ public function text($message)
}

/**
* {@inheritdoc}
* Formats a command comment.
*
* @param string|array $message
*/
public function comment($message)
{
$this->autoPrependText();

$messages = is_array($message) ? array_values($message) : array($message);
foreach ($messages as $message) {
$this->writeln(sprintf(' // %s', $message));
foreach ($messages as &$message) {
$message = $this->getFormatter()->format($message);
}

$this->block($messages, null, null, ' // ');
}

/**
Expand Down
@@ -0,0 +1,13 @@
<?php

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

//Ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->comment(
'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,0 +1,6 @@

// 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

Expand Up @@ -11,5 +11,8 @@ Lorem ipsum dolor sit amet
consectetur adipiscing elit

Lorem ipsum dolor sit amet
// Lorem ipsum dolor sit amet
// consectetur adipiscing elit

// Lorem ipsum dolor sit amet
//
// consectetur adipiscing elit

0 comments on commit dfc0c81

Please sign in to comment.