@@ -43,6 +43,7 @@ class ProgressBar
4343 private $ formatLineCount ;
4444 private $ messages ;
4545 private $ overwrite = true ;
46+ private $ formatSetByUser = false ;
4647
4748 private static $ formatters ;
4849 private static $ formats ;
@@ -72,7 +73,7 @@ public function __construct(OutputInterface $output, $max = 0)
7273 }
7374 }
7475
75- $ this ->setFormat ($ this ->determineBestFormat ());
76+ $ this ->setFormatInternal ($ this ->determineBestFormat ());
7677
7778 $ this ->startTime = time ();
7879 }
@@ -310,16 +311,8 @@ public function getProgressCharacter()
310311 */
311312 public function setFormat ($ format )
312313 {
313- // try to use the _nomax variant if available
314- if (!$ this ->max && null !== self ::getFormatDefinition ($ format .'_nomax ' )) {
315- $ this ->format = self ::getFormatDefinition ($ format .'_nomax ' );
316- } elseif (null !== self ::getFormatDefinition ($ format )) {
317- $ this ->format = self ::getFormatDefinition ($ format );
318- } else {
319- $ this ->format = $ format ;
320- }
321-
322- $ this ->formatLineCount = substr_count ($ this ->format , "\n" );
314+ $ this ->formatSetByUser = true ;
315+ $ this ->setFormatInternal ($ format );
323316 }
324317
325318 /**
@@ -345,6 +338,10 @@ public function start($max = null)
345338
346339 if (null !== $ max ) {
347340 $ this ->setMaxSteps ($ max );
341+
342+ if (!$ this ->formatSetByUser ) {
343+ $ this ->setFormatInternal ($ this ->determineBestFormat ());
344+ }
348345 }
349346
350347 $ this ->display ();
@@ -478,6 +475,25 @@ public function clear()
478475 $ this ->overwrite (str_repeat ("\n" , $ this ->formatLineCount ));
479476 }
480477
478+ /**
479+ * Sets the progress bar format.
480+ *
481+ * @param string $format The format
482+ */
483+ private function setFormatInternal ($ format )
484+ {
485+ // try to use the _nomax variant if available
486+ if (!$ this ->max && null !== self ::getFormatDefinition ($ format .'_nomax ' )) {
487+ $ this ->format = self ::getFormatDefinition ($ format .'_nomax ' );
488+ } elseif (null !== self ::getFormatDefinition ($ format )) {
489+ $ this ->format = self ::getFormatDefinition ($ format );
490+ } else {
491+ $ this ->format = $ format ;
492+ }
493+
494+ $ this ->formatLineCount = substr_count ($ this ->format , "\n" );
495+ }
496+
481497 /**
482498 * Sets the progress bar maximal steps.
483499 *
0 commit comments