12 namespace Symfony\Component\Console\Helper;
60 if (!$this->output->isDecorated()) {
64 if ($this->max > 10) {
72 $this->startTime = time();
85 if (!self::$formatters) {
86 self::$formatters = self::initPlaceholderFormatters();
89 self::$formatters[$name] = $callable;
101 if (!self::$formatters) {
102 self::$formatters = self::initPlaceholderFormatters();
105 return isset(self::$formatters[$name]) ? self::$formatters[$name] : null;
118 if (!self::$formats) {
119 self::$formats = self::initFormats();
122 self::$formats[$name] =
$format;
134 if (!self::$formats) {
135 self::$formats = self::initFormats();
138 return isset(self::$formats[$name]) ? self::$formats[$name] : null;
143 $this->messages[$name] = $message;
148 return $this->messages[$name];
180 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 2.6 and will be removed in 3.0. Use the getProgress() method instead.', E_USER_DEPRECATED);
224 $this->barWidth = (int) $size;
244 $this->barChar = $char;
254 if (null === $this->barChar) {
268 $this->emptyBarChar = $char;
288 $this->progressChar = $char;
309 if (!$this->max && null !== self::getFormatDefinition(
$format.
'_nomax')) {
310 $this->format = self::getFormatDefinition(
$format.
'_nomax');
312 $this->format = self::getFormatDefinition(
$format);
317 $this->formatLineCount = substr_count($this->format,
"\n");
327 $this->redrawFreq = (int) $freq;
337 $this->startTime = time();
339 $this->percent = 0.0;
371 @trigger_error(
'The '.__METHOD__.
' method is deprecated since version 2.6 and will be removed in 3.0. Use the setProgress() method instead.', E_USER_DEPRECATED);
396 if ($step < $this->step) {
397 throw new \LogicException(
'You can\'t regress the progress bar.');
400 if ($this->max &&
$step > $this->max) {
404 $prevPeriod = (int) ($this->step / $this->redrawFreq);
405 $currPeriod = (int) (
$step / $this->redrawFreq);
407 $this->percent = $this->max ? (float) $this->step / $this->max : 0;
408 if ($prevPeriod !== $currPeriod || $this->max ===
$step) {
422 if ($this->step === $this->max && !$this->
overwrite) {
443 $this->
overwrite(preg_replace_callback(
"{%([a-z\-_]+)(?:\:([^%]+))?%}i",
function ($matches) use ($self,
$output,
$messages) {
444 if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
445 $text = call_user_func($formatter, $self,
$output);
452 if (isset($matches[2])) {
453 $text = sprintf(
'%'.$matches[2], $text);
473 $this->
overwrite(str_repeat(
"\n", $this->formatLineCount));
483 $this->max = max(0, (
int)
$max);
494 $lines = explode(
"\n", $message);
497 if (null !== $this->lastMessagesLength) {
498 foreach ($lines as $i => $line) {
500 $lines[$i] = str_pad($line, $this->lastMessagesLength,
"\x20", STR_PAD_RIGHT);
507 $this->output->write(
"\x0D");
508 }
elseif ($this->step > 0) {
510 $this->output->writeln(
'');
513 if ($this->formatLineCount) {
514 $this->output->write(sprintf(
"\033[%dA", $this->formatLineCount));
516 $this->output->write(implode(
"\n", $lines));
518 $this->lastMessagesLength = 0;
519 foreach ($lines as $line) {
521 if ($len > $this->lastMessagesLength) {
522 $this->lastMessagesLength = $len;
529 switch ($this->output->getVerbosity()) {
532 return $this->max ?
'verbose' :
'verbose_nomax';
534 return $this->max ?
'very_verbose' :
'very_verbose_nomax';
536 return $this->max ?
'debug' :
'debug_nomax';
538 return $this->max ?
'normal' :
'normal_nomax';
560 throw new \LogicException(
'Unable to display the remaining time if the maximum number of steps is not set.');
573 throw new \LogicException(
'Unable to display the estimated time if the maximum number of steps is not set.');
602 'normal' =>
' %current%/%max% [%bar%] %percent:3s%%',
603 'normal_nomax' =>
' %current% [%bar%]',
605 'verbose' =>
' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%',
606 'verbose_nomax' =>
' %current% [%bar%] %elapsed:6s%',
608 'very_verbose' =>
' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%',
609 'very_verbose_nomax' =>
' %current% [%bar%] %elapsed:6s%',
611 'debug' =>
' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%',
612 'debug_nomax' =>
' %current% [%bar%] %elapsed:6s% %memory:6s%',