This commit is contained in:
TiclemFR
2023-12-29 16:00:02 +01:00
parent 9d79d7c0c6
commit 884eb3011a
8361 changed files with 1160554 additions and 4 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace Laravel\Prompts\Output;
class BufferedConsoleOutput extends ConsoleOutput
{
/**
* The output buffer.
*/
protected string $buffer = '';
/**
* Empties the buffer and returns its content.
*/
public function fetch(): string
{
$content = $this->buffer;
$this->buffer = '';
return $content;
}
/**
* Return the content of the buffer.
*/
public function content(): string
{
return $this->buffer;
}
/**
* Write to the output buffer.
*/
protected function doWrite(string $message, bool $newline): void
{
$this->buffer .= $message;
if ($newline) {
$this->buffer .= \PHP_EOL;
}
}
/**
* Write output directly, bypassing newline capture.
*/
public function writeDirectly(string $message): void
{
$this->doWrite($message, false);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Laravel\Prompts\Output;
use Symfony\Component\Console\Output\ConsoleOutput as SymfonyConsoleOutput;
class ConsoleOutput extends SymfonyConsoleOutput
{
/**
* How many new lines were written by the last output.
*/
protected int $newLinesWritten = 1;
/**
* How many new lines were written by the last output.
*/
public function newLinesWritten(): int
{
return $this->newLinesWritten;
}
/**
* Write the output and capture the number of trailing new lines.
*/
protected function doWrite(string $message, bool $newline): void
{
parent::doWrite($message, $newline);
if ($newline) {
$message .= \PHP_EOL;
}
$trailingNewLines = strlen($message) - strlen(rtrim($message, \PHP_EOL));
if (trim($message) === '') {
$this->newLinesWritten += $trailingNewLines;
} else {
$this->newLinesWritten = $trailingNewLines;
}
}
/**
* Write output directly, bypassing newline capture.
*/
public function writeDirectly(string $message): void
{
parent::doWrite($message, false);
}
}