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\FormatterCode
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);
}