Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ConsoleSectionOutput.php

function ConsoleSectionOutput::addContent

@internal

1 call to ConsoleSectionOutput::addContent()
ConsoleSectionOutput::doWrite in vendor/symfony/console/Output/ConsoleSectionOutput.php
Writes a message to the output.

File

vendor/symfony/console/Output/ConsoleSectionOutput.php, line 108

Class

ConsoleSectionOutput
@author Pierre du Plessis <pdples@gmail.com> @author Gabriel Ostrolucký <gabriel.ostrolucky@gmail.com>

Namespace

Symfony\Component\Console\Output

Code

public function addContent(string $input, bool $newline = true) : int {
    $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;
    }
    $this->lines += $linesAdded;
    return $linesAdded;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal