@@ -67,6 +67,8 @@ public function __construct(OutputInterface $output, $max = 0)
6767 if (!self ::$ formats ) {
6868 self ::$ formats = self ::initFormats ();
6969 }
70+
71+ $ this ->setFormat ($ this ->determineBestFormat ());
7072 }
7173
7274 /**
@@ -274,7 +276,15 @@ public function getProgressCharacter()
274276 */
275277 public function setFormat ($ format )
276278 {
277- $ this ->format = isset (self ::$ formats [$ format ]) ? self ::$ formats [$ format ] : $ format ;
279+ // try to use the _nomax variant if available
280+ if (!$ this ->max && isset (self ::$ formats [$ format .'_nomax ' ])) {
281+ $ this ->format = self ::$ formats [$ format .'_nomax ' ];
282+ } elseif (isset (self ::$ formats [$ format ])) {
283+ $ this ->format = self ::$ formats [$ format ];
284+ } else {
285+ $ this ->format = $ format ;
286+ }
287+
278288 $ this ->formatLineCount = substr_count ($ this ->format , "\n" );
279289 }
280290
@@ -299,10 +309,6 @@ public function start()
299309 $ this ->lastMessagesLength = 0 ;
300310 $ this ->barCharOriginal = '' ;
301311
302- if (null === $ this ->format ) {
303- $ this ->setFormat ($ this ->determineBestFormat ());
304- }
305-
306312 if (!$ this ->max ) {
307313 $ this ->barCharOriginal = $ this ->barChar ;
308314 $ this ->barChar = $ this ->emptyBarChar ;
@@ -457,12 +463,13 @@ private function overwrite($message)
457463 private function determineBestFormat ()
458464 {
459465 switch ($ this ->output ->getVerbosity ()) {
460- case OutputInterface::VERBOSITY_QUIET :
461- return $ this ->max > 0 ? 'quiet ' : 'quiet_nomax ' ;
466+ // OutputInterface::VERBOSITY_QUIET: display is disabled anyway
462467 case OutputInterface::VERBOSITY_VERBOSE :
468+ return $ this ->max > 0 ? 'verbose ' : 'verbose_nomax ' ;
463469 case OutputInterface::VERBOSITY_VERY_VERBOSE :
470+ return $ this ->max > 0 ? 'very_verbose ' : 'very_verbose_nomax ' ;
464471 case OutputInterface::VERBOSITY_DEBUG :
465- return $ this ->max > 0 ? 'verbose ' : 'verbose_nomax ' ;
472+ return $ this ->max > 0 ? 'debug ' : 'debug_nomax ' ;
466473 default :
467474 return $ this ->max > 0 ? 'normal ' : 'normal_nomax ' ;
468475 }
@@ -528,12 +535,17 @@ private static function initPlaceholderFormatters()
528535 private static function initFormats ()
529536 {
530537 return array (
531- 'quiet ' => ' %percent%% ' ,
532- 'normal ' => ' %current%/%max% [%bar%] %percent:3s%% ' ,
533- 'verbose ' => ' %current%/%max% [%bar%] %percent:3s%% Elapsed: %elapsed:6s% ' ,
534- 'quiet_nomax ' => ' %current% ' ,
535- 'normal_nomax ' => ' %current% [%bar%] ' ,
536- 'verbose_nomax ' => ' %current% [%bar%] Elapsed: %elapsed:6s% ' ,
538+ 'normal ' => ' %current%/%max% [%bar%] %percent:3s%% ' ,
539+ 'normal_nomax ' => ' %current% [%bar%] ' ,
540+
541+ 'verbose ' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% ' ,
542+ 'verbose_nomax ' => ' %current% [%bar%] %percent:3s%% %elapsed:6s% ' ,
543+
544+ 'very_verbose ' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% ' ,
545+ 'very_verbose_nomax ' => ' %current% [%bar%] %percent:3s%% %elapsed:6s% ' ,
546+
547+ 'debug ' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s% ' ,
548+ 'debug_nomax ' => ' %current% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s% ' ,
537549 );
538550 }
539551}
0 commit comments