mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
Update composer
This commit is contained in:
parent
330cdbe615
commit
0c83c9a678
442 changed files with 9523 additions and 10793 deletions
|
@ -21,11 +21,10 @@ use Symfony\Component\Console\Terminal;
|
|||
*/
|
||||
class ConsoleSectionOutput extends StreamOutput
|
||||
{
|
||||
private array $content = [];
|
||||
private int $lines = 0;
|
||||
private array $sections;
|
||||
private Terminal $terminal;
|
||||
private int $maxHeight = 0;
|
||||
private $content = [];
|
||||
private $lines = 0;
|
||||
private $sections;
|
||||
private $terminal;
|
||||
|
||||
/**
|
||||
* @param resource $stream
|
||||
|
@ -39,29 +38,10 @@ class ConsoleSectionOutput extends StreamOutput
|
|||
$this->terminal = new Terminal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a maximum number of lines for this section.
|
||||
*
|
||||
* When more lines are added, the section will automatically scroll to the
|
||||
* end (i.e. remove the first lines to comply with the max height).
|
||||
*/
|
||||
public function setMaxHeight(int $maxHeight): void
|
||||
{
|
||||
// when changing max height, clear output of current section and redraw again with the new height
|
||||
$previousMaxHeight = $this->maxHeight;
|
||||
$this->maxHeight = $maxHeight;
|
||||
$existingContent = $this->popStreamContentUntilCurrentSection($previousMaxHeight ? min($previousMaxHeight, $this->lines) : $this->lines);
|
||||
|
||||
parent::doWrite($this->getVisibleContent(), false);
|
||||
parent::doWrite($existingContent, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears previous output for this section.
|
||||
*
|
||||
* @param int $lines Number of lines to clear. If null, then the entire output of this section is cleared
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear(?int $lines = null)
|
||||
{
|
||||
|
@ -70,7 +50,7 @@ class ConsoleSectionOutput extends StreamOutput
|
|||
}
|
||||
|
||||
if ($lines) {
|
||||
array_splice($this->content, -$lines);
|
||||
array_splice($this->content, -($lines * 2)); // Multiply lines by 2 to cater for each new line added between content
|
||||
} else {
|
||||
$lines = $this->lines;
|
||||
$this->content = [];
|
||||
|
@ -78,15 +58,15 @@ class ConsoleSectionOutput extends StreamOutput
|
|||
|
||||
$this->lines -= $lines;
|
||||
|
||||
parent::doWrite($this->popStreamContentUntilCurrentSection($this->maxHeight ? min($this->maxHeight, $lines) : $lines), false);
|
||||
parent::doWrite($this->popStreamContentUntilCurrentSection($lines), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the previous output with a new message.
|
||||
*
|
||||
* @return void
|
||||
* @param array|string $message
|
||||
*/
|
||||
public function overwrite(string|iterable $message)
|
||||
public function overwrite($message)
|
||||
{
|
||||
$this->clear();
|
||||
$this->writeln($message);
|
||||
|
@ -97,110 +77,34 @@ class ConsoleSectionOutput extends StreamOutput
|
|||
return implode('', $this->content);
|
||||
}
|
||||
|
||||
public function getVisibleContent(): string
|
||||
{
|
||||
if (0 === $this->maxHeight) {
|
||||
return $this->getContent();
|
||||
}
|
||||
|
||||
return implode('', \array_slice($this->content, -$this->maxHeight));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function addContent(string $input, bool $newline = true): int
|
||||
public function addContent(string $input)
|
||||
{
|
||||
$width = $this->terminal->getWidth();
|
||||
$lines = explode(\PHP_EOL, $input);
|
||||
$linesAdded = 0;
|
||||
$count = \count($lines) - 1;
|
||||
foreach ($lines as $i => $lineContent) {
|
||||
// re-add the line break (that has been removed in the above `explode()` for
|
||||
// - every line that is not the last line
|
||||
// - if $newline is required, also add it to the last line
|
||||
if ($i < $count || $newline) {
|
||||
$lineContent .= \PHP_EOL;
|
||||
}
|
||||
|
||||
// skip line if there is no text (or newline for that matter)
|
||||
if ('' === $lineContent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// For the first line, check if the previous line (last entry of `$this->content`)
|
||||
// needs to be continued (i.e. does not end with a line break).
|
||||
if (0 === $i
|
||||
&& (false !== $lastLine = end($this->content))
|
||||
&& !str_ends_with($lastLine, \PHP_EOL)
|
||||
) {
|
||||
// deduct the line count of the previous line
|
||||
$this->lines -= (int) ceil($this->getDisplayLength($lastLine) / $width) ?: 1;
|
||||
// concatenate previous and new line
|
||||
$lineContent = $lastLine.$lineContent;
|
||||
// replace last entry of `$this->content` with the new expanded line
|
||||
array_splice($this->content, -1, 1, $lineContent);
|
||||
} else {
|
||||
// otherwise just add the new content
|
||||
$this->content[] = $lineContent;
|
||||
}
|
||||
|
||||
$linesAdded += (int) ceil($this->getDisplayLength($lineContent) / $width) ?: 1;
|
||||
foreach (explode(\PHP_EOL, $input) as $lineContent) {
|
||||
$this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1;
|
||||
$this->content[] = $lineContent;
|
||||
$this->content[] = \PHP_EOL;
|
||||
}
|
||||
|
||||
$this->lines += $linesAdded;
|
||||
|
||||
return $linesAdded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function addNewLineOfInputSubmit(): void
|
||||
{
|
||||
$this->content[] = \PHP_EOL;
|
||||
++$this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWrite(string $message, bool $newline)
|
||||
{
|
||||
// Simulate newline behavior for consistent output formatting, avoiding extra logic
|
||||
if (!$newline && str_ends_with($message, \PHP_EOL)) {
|
||||
$message = substr($message, 0, -\strlen(\PHP_EOL));
|
||||
$newline = true;
|
||||
}
|
||||
|
||||
if (!$this->isDecorated()) {
|
||||
parent::doWrite($message, $newline);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the previous line (last entry of `$this->content`) needs to be continued
|
||||
// (i.e. does not end with a line break). In which case, it needs to be erased first.
|
||||
$linesToClear = $deleteLastLine = ($lastLine = end($this->content) ?: '') && !str_ends_with($lastLine, \PHP_EOL) ? 1 : 0;
|
||||
$erasedContent = $this->popStreamContentUntilCurrentSection();
|
||||
|
||||
$linesAdded = $this->addContent($message, $newline);
|
||||
$this->addContent($message);
|
||||
|
||||
if ($lineOverflow = $this->maxHeight > 0 && $this->lines > $this->maxHeight) {
|
||||
// on overflow, clear the whole section and redraw again (to remove the first lines)
|
||||
$linesToClear = $this->maxHeight;
|
||||
}
|
||||
|
||||
$erasedContent = $this->popStreamContentUntilCurrentSection($linesToClear);
|
||||
|
||||
if ($lineOverflow) {
|
||||
// redraw existing lines of the section
|
||||
$previousLinesOfSection = \array_slice($this->content, $this->lines - $this->maxHeight, $this->maxHeight - $linesAdded);
|
||||
parent::doWrite(implode('', $previousLinesOfSection), false);
|
||||
}
|
||||
|
||||
// if the last line was removed, re-print its content together with the new content.
|
||||
// otherwise, just print the new content.
|
||||
parent::doWrite($deleteLastLine ? $lastLine.$message : $message, true);
|
||||
parent::doWrite($message, true);
|
||||
parent::doWrite($erasedContent, false);
|
||||
}
|
||||
|
||||
|
@ -218,13 +122,8 @@ class ConsoleSectionOutput extends StreamOutput
|
|||
break;
|
||||
}
|
||||
|
||||
$numberOfLinesToClear += $section->maxHeight ? min($section->lines, $section->maxHeight) : $section->lines;
|
||||
if ('' !== $sectionContent = $section->getVisibleContent()) {
|
||||
if (!str_ends_with($sectionContent, \PHP_EOL)) {
|
||||
$sectionContent .= \PHP_EOL;
|
||||
}
|
||||
$erasedContent[] = $sectionContent;
|
||||
}
|
||||
$numberOfLinesToClear += $section->lines;
|
||||
$erasedContent[] = $section->getContent();
|
||||
}
|
||||
|
||||
if ($numberOfLinesToClear > 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue