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

Breadcrumb

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

function OutputFormatter::applyCurrentStyle

Applies current style from stack to text, if must be applied.

1 call to OutputFormatter::applyCurrentStyle()
OutputFormatter::formatAndWrap in vendor/symfony/console/Formatter/OutputFormatter.php
Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).

File

vendor/symfony/console/Formatter/OutputFormatter.php, line 214

Class

OutputFormatter
Formatter class for console output.

Namespace

Symfony\Component\Console\Formatter

Code

private function applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength) : string {
    if ('' === $text) {
        return '';
    }
    if (!$width) {
        return $this->isDecorated() ? $this->styleStack
            ->getCurrent()
            ->apply($text) : $text;
    }
    if (!$currentLineLength && '' !== $current) {
        $text = ltrim($text);
    }
    if ($currentLineLength) {
        $prefix = substr($text, 0, $i = $width - $currentLineLength) . "\n";
        $text = substr($text, $i);
    }
    else {
        $prefix = '';
    }
    preg_match('~(\\n)$~', $text, $matches);
    $text = $prefix . $this->addLineBreaks($text, $width);
    $text = rtrim($text, "\n") . ($matches[1] ?? '');
    if (!$currentLineLength && '' !== $current && !str_ends_with($current, "\n")) {
        $text = "\n" . $text;
    }
    $lines = explode("\n", $text);
    foreach ($lines as $line) {
        $currentLineLength += \strlen($line);
        if ($width <= $currentLineLength) {
            $currentLineLength = 0;
        }
    }
    if ($this->isDecorated()) {
        foreach ($lines as $i => $line) {
            $lines[$i] = $this->styleStack
                ->getCurrent()
                ->apply($line);
        }
    }
    return implode("\n", $lines);
}

API Navigation

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