-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
@@ -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)))); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 👍
@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. Do you think the |
@@ -92,7 +92,8 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa | ||
} | ||
} | ||
|
||
$this->writeln(implode("\n", $lines)."\n"); | ||
$lines[] = ''; | ||
$this->writeln($lines); |
There was a problem hiding this comment.
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, ''));
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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('')));
There was a problem hiding this comment.
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 :)
…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 :  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
…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 :  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
Fix EOL inconsistency - especially on Windows platforms where both
LF
andCRLF
were mixed - by relying as much as possible on output implementation.Indeed,
PHP_EOL
is used inOutputStyle::newLine()
andStreamOutput
, so there was no reason for usingLF
inSymfonyStyle
.However,
BufferedOutput
usesLF
. Then, EOL inconsistency might still be a problem if someone is usingSymfonyStyle
/OutputStyle
with aBufferedOutput
instance.