Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] SymfonyStyle : EOL consistency #14741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2015
Merged

[Console] SymfonyStyle : EOL consistency #14741

merged 1 commit into from
Jun 8, 2015

Conversation

ogizanagi
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Fix EOL inconsistency - especially on Windows platforms where both LF and CRLF were mixed - by relying as much as possible on output implementation.

Indeed, PHP_EOL is used in OutputStyle::newLine() and StreamOutput, so there was no reason for using LF in SymfonyStyle.

However, BufferedOutput uses LF. Then, EOL inconsistency might still be a problem if someone is using SymfonyStyle/OutputStyle with a BufferedOutput instance.

@@ -100,7 +100,7 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa
*/
public function title($message)
{
$this->writeln(sprintf("\n<comment>%s</>\n<comment>%s</>\n", $message, str_repeat('=', strlen($message))));
$this->writeln(sprintf('<comment>%s</>'.PHP_EOL.'<comment>%s</>'.PHP_EOL, $message, str_repeat('=', strlen($message))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing PHP_EOL at the beginning of the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@ogizanagi
Copy link
Contributor Author

@aitboudad : Actually, your comments gave me another idea. What do you think of this new suggestion ? The output is strictly equivalent, and relies on the real output instance in use.
It almost solves the issue using BufferedOutput with SymfonyStyle.

Do you think the BufferedOutput::doWrite() method should convert any PHP_EOL to LF ? Is there anything preventing this regarding BC ?
Or should outputs expose the EOL char in use ?

@ogizanagi ogizanagi changed the title [Console] SymfonyStyle : use PHP_EOL instead of LF [Console] SymfonyStyle : EOL consistency May 24, 2015
@@ -92,7 +92,8 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa
}
}

$this->writeln(implode("\n", $lines)."\n");
$lines[] = '';
$this->writeln($lines);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use array_push here instead $lines[] = ''; ?

$this->writeln(array_push($lines, ''));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aitboudad : array_push returns the new number of elements in the array. So we will not be able to inline those statements using array_push.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this would be possible:

$this->writeln(array_merge($lines, (array) ''));
//or
$this->writeln(array_merge($lines, array('')));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave it as it is :)

@fabpot fabpot merged commit 260702e into symfony:2.7 Jun 8, 2015
fabpot added a commit that referenced this pull request Jun 8, 2015
…nagi)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] SymfonyStyle : fix & automate block gaps.

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

---
Depends on #14741

---
## What it does
- autoprepend appropriate blocks (like cautions, titles, sections, ...) by the correct number of blank lines considering history.
- handle automatically most of the SymfonyStyle guide line breaks and gaps. Fix things such as unwanted double blank lines between titles and admonitions.
- test outputs
- fix an issue using questions with SymfonyStyle, which should not output extra blank lines when using with a non-interactive input.

## Description

`SymfonyStyle` is great, but there are some issues, mostly when using blocks (text blocks, titles and admonitions): some extra blank lines might be generated.

Plus, on the contrary, some line breaks or blank lines around blocks are missing, and the developer need to handle this himself by polluting his code with ugly `if` and `newLine()` statements.

### Before / After :

![screenshot 2015-05-13 a 00 11 59](https://cloud.githubusercontent.com/assets/2211145/7600572/ccfa8904-f90c-11e4-999f-d89612360424.PNG)

As you can see, it's still up to the developper to end his command by a blank line (unless using a block like `SymfonyStyle::success()`) in order to distinct different commands outputs more efficiently.

Everything else is now handled properly, and automatically, according to the rules exposed in the symfony console style guide published some time ago by @javiereguiluz .
Questions (not exposed in the above output) are considered as blocks, and follow, for instance, the same conditions than admonitions: 1 blank line before and after, no more (although, you'll still be able to output more blank lines yourself, using `newLine`).

Commits
-------

fc598ff [Console] SymfonyStyle : fix & automate block gaps.
260702e [Console] SymfonyStyle : Improve EOL consistency by relying on output instance
fabpot added a commit to symfony/console that referenced this pull request Jun 8, 2015
…nagi)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] SymfonyStyle : fix & automate block gaps.

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

---
Depends on symfony/symfony#14741

---
## What it does
- autoprepend appropriate blocks (like cautions, titles, sections, ...) by the correct number of blank lines considering history.
- handle automatically most of the SymfonyStyle guide line breaks and gaps. Fix things such as unwanted double blank lines between titles and admonitions.
- test outputs
- fix an issue using questions with SymfonyStyle, which should not output extra blank lines when using with a non-interactive input.

## Description

`SymfonyStyle` is great, but there are some issues, mostly when using blocks (text blocks, titles and admonitions): some extra blank lines might be generated.

Plus, on the contrary, some line breaks or blank lines around blocks are missing, and the developer need to handle this himself by polluting his code with ugly `if` and `newLine()` statements.

### Before / After :

![screenshot 2015-05-13 a 00 11 59](https://cloud.githubusercontent.com/assets/2211145/7600572/ccfa8904-f90c-11e4-999f-d89612360424.PNG)

As you can see, it's still up to the developper to end his command by a blank line (unless using a block like `SymfonyStyle::success()`) in order to distinct different commands outputs more efficiently.

Everything else is now handled properly, and automatically, according to the rules exposed in the symfony console style guide published some time ago by @javiereguiluz .
Questions (not exposed in the above output) are considered as blocks, and follow, for instance, the same conditions than admonitions: 1 blank line before and after, no more (although, you'll still be able to output more blank lines yourself, using `newLine`).

Commits
-------

fc598ff [Console] SymfonyStyle : fix & automate block gaps.
260702e [Console] SymfonyStyle : Improve EOL consistency by relying on output instance
@ogizanagi ogizanagi deleted the sfstyle/eol_consistency branch June 8, 2015 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.