function ProgressBar::buildLine
1 call to ProgressBar::buildLine()
- ProgressBar::display in vendor/
symfony/ console/ Helper/ ProgressBar.php - Outputs the current progress string.
File
-
vendor/
symfony/ console/ Helper/ ProgressBar.php, line 609
Class
- ProgressBar
- The ProgressBar provides helpers to display progress output.
Namespace
Symfony\Component\Console\HelperCode
private function buildLine() : string {
\assert(null !== $this->format);
$regex = '{%([a-z\\-_]+)(?:\\:([^%]+))?%}i';
$callback = function ($matches) {
if ($formatter = $this->getPlaceholderFormatter($matches[1])) {
$text = $formatter($this, $this->output);
}
elseif (isset($this->messages[$matches[1]])) {
$text = $this->messages[$matches[1]];
}
else {
return $matches[0];
}
if (isset($matches[2])) {
$text = \sprintf('%' . $matches[2], $text);
}
return $text;
};
$line = preg_replace_callback($regex, $callback, $this->format);
// gets string length for each sub line with multiline format
$linesLength = array_map(fn($subLine) => Helper::width(Helper::removeDecoration($this->output
->getFormatter(), rtrim($subLine, "\r"))), explode("\n", $line));
$linesWidth = max($linesLength);
$terminalWidth = $this->terminal
->getWidth();
if ($linesWidth <= $terminalWidth) {
return $line;
}
$this->setBarWidth($this->barWidth - $linesWidth + $terminalWidth);
return preg_replace_callback($regex, $callback, $this->format);
}