@@ -43,6 +43,7 @@ class ProgressBar
43
43
private $ formatLineCount ;
44
44
private $ messages ;
45
45
private $ overwrite = true ;
46
+ private $ formatSetByUser = false ;
46
47
47
48
private static $ formatters ;
48
49
private static $ formats ;
@@ -72,7 +73,7 @@ public function __construct(OutputInterface $output, $max = 0)
72
73
}
73
74
}
74
75
75
- $ this ->setFormat ($ this ->determineBestFormat ());
76
+ $ this ->setFormatInternal ($ this ->determineBestFormat ());
76
77
77
78
$ this ->startTime = time ();
78
79
}
@@ -310,16 +311,8 @@ public function getProgressCharacter()
310
311
*/
311
312
public function setFormat ($ format )
312
313
{
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 );
323
316
}
324
317
325
318
/**
@@ -345,6 +338,10 @@ public function start($max = null)
345
338
346
339
if (null !== $ max ) {
347
340
$ this ->setMaxSteps ($ max );
341
+
342
+ if (!$ this ->formatSetByUser ) {
343
+ $ this ->setFormatInternal ($ this ->determineBestFormat ());
344
+ }
348
345
}
349
346
350
347
$ this ->display ();
@@ -478,6 +475,25 @@ public function clear()
478
475
$ this ->overwrite (str_repeat ("\n" , $ this ->formatLineCount ));
479
476
}
480
477
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
+
481
497
/**
482
498
* Sets the progress bar maximal steps.
483
499
*
0 commit comments