Skip to content

Commit a5e48ed

Browse files
committed
fix: check for the correct line endings to support Windows
1 parent 214edcd commit a5e48ed

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Command/Command.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\Console\Output\OutputInterface;
2020

2121
use function assert;
22-
use function explode;
2322
use function implode;
2423
use function mb_strlen;
2524
use function preg_replace;
@@ -91,9 +90,9 @@ public function setHelp(string $help): static
9190

9291
private function wrapHelp(string $message): string
9392
{
94-
$message = (string) preg_replace('/(?<!\n)\n(?!\s)/m', ' ', $message);
95-
$message = str_replace("\n", PHP_EOL, $message);
96-
$lines = explode("\n", $message);
93+
$message = (string) preg_replace('/(?<!\n|\r|\r\n)\R(?!\s)/', ' ', $message);
94+
$message = (string) preg_replace('/\R/', PHP_EOL, $message);
95+
$lines = preg_split('/\R/', $message) ?: [];
9796

9897
$wrapped = [];
9998

src/Command/ProcessCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use function trim;
2626

2727
use const FILTER_VALIDATE_FLOAT;
28+
use const PHP_EOL;
2829

2930
abstract class ProcessCommand extends Command
3031
{
@@ -66,11 +67,14 @@ public function setHelp(string $help): static
6667
$executable = $this->getExecutablePath();
6768
$name = $this->getExecutableName();
6869

69-
$programInfo = "\n\n---\n\nThis command uses $name. On your system, $name is ";
70+
// Double-spaced lines.
71+
$ds = PHP_EOL . PHP_EOL;
72+
73+
$programInfo = "$ds---{$ds}This command uses $name. On your system, $name is ";
7074

7175
if ($executable === null) {
7276
$programInfo .= '<error>not installed</error>.';
73-
$programInfo .= "\n\n";
77+
$programInfo .= $ds;
7478
$programInfo .= $this->getInstallationMessage();
7579
} else {
7680
if (str_starts_with((string) $this->getExecutablePath(), $this->configuration->projectRoot)) {

0 commit comments

Comments
 (0)