-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Description
Laravel Prompts Version
0.3.5
Laravel Version
12.15.0
PHP Version
8.4.6
Operating System & Version
Windows 11
Terminal Application
VS Code
Description
Inside Laravel\Prompts\Output\ConsoleOutput::doWrite()
, trailing new lines are calculated like so:
$trailingNewLines = strlen($message) - strlen(rtrim($message, \PHP_EOL));
On Windows PHP_EOL
is 2 chars \r\n
.
Steps To Reproduce
Can't really showcase well, because it's more of an internal thing, but for a unorthodox reproduction see:
// Somewhere early in Laravel's lifecycle, e.g. in Provider...
$output = new \Laravel\Prompts\Output\ConsoleOutput;
dump($output->newLinesWritten()); // 1
$output->writeln("Hi!");
dd($output->newLinesWritten()); // 2
Potential solution
Since it's not uncommon for people to write "\n"
instead of PHP_EOL
, it might be better to only count \n
s?
$trailingNewLines = strlen($message) - strlen(rtrim($message, \PHP_EOL));
if (\PHP_OS_FAMILY === 'Windows') $trailingNewLines = substr_count(substr($message, $trailingNewLines), "\n");
Metadata
Metadata
Assignees
Labels
No labels