@@ -175,7 +175,6 @@ current progress of the bar. Here is a list of the built-in placeholders:
175175* ``remaining ``: The remaining time to complete the task (not available if no max is defined);
176176* ``estimated ``: The estimated time to complete the task (not available if no max is defined);
177177* ``memory ``: The current memory usage;
178- * ``message ``: The current message attached to the progress bar.
179178
180179For instance, here is how you could set the format to be the same as the
181180``debug `` one::
@@ -186,20 +185,6 @@ Notice the ``:6s`` part added to some placeholders? That's how you can tweak
186185the appearance of the bar (formatting and alignment). The part after the colon
187186(``: ``) is used to set the ``sprintf `` format of the string.
188187
189- The ``message `` placeholder is a bit special as you must set the value
190- yourself::
191-
192- $bar->setMessage('Task starts');
193- $bar->start();
194-
195- $bar->setMessage('Task in progress...');
196- $bar->advance();
197-
198- // ...
199-
200- $bar->setMessage('Task is finished');
201- $bar->finish();
202-
203188Instead of setting the format for a given instance of a progress bar, you can
204189also define global formats::
205190
@@ -313,25 +298,33 @@ that displays the number of remaining steps::
313298Custom Messages
314299~~~~~~~~~~~~~~~
315300
316- The `` %message% `` placeholder allows you to specify a custom message to be
317- displayed with the progress bar. But if you need more than one, just define
318- your own::
301+ If you want to show some fixed text or generic message, you can define custom
302+ placeholders to be displayed with the progress bar, after defining them in a
303+ custom format.
319304
320- $bar->setMessage('Task starts');
321- $bar->setMessage('', 'filename');
322- $bar->start();
305+ By default, the ``setMessage() `` method implies ``message `` as the name of the
306+ placeholder, but if you need more than one, you have just to just define your
307+ own::
308+
309+ $progressBar = new ProgressBar($output, 100);
310+ $progressBar->setFormatDefinition('custom', ' %current%/%max% -- %message% %filename%');
311+ $progressBar->setFormat('custom');
312+ $progressBar->setMessage('Start');
313+
314+ $progressBar->start();
315+ // 0/100 -- Start
316+
317+ $progressBar->advance();
318+ $progressBar->setMessage('Task is in progress...');
319+ // 1/100 -- Task is in progress...
323320
324- $bar->setMessage('Task is in progress...');
325321 while ($file = array_pop($files)) {
326322 $bar->setMessage($filename, 'filename');
327323 $bar->advance();
324+ // 2/100 -- Task is in progress... $filename
328325 }
329326
330327 $bar->setMessage('Task is finished');
331328 $bar->setMessage('', 'filename');
332329 $bar->finish();
333-
334- For the ``filename `` to be part of the progress bar, just add the
335- ``%filename% `` placeholder in your format::
336-
337- $bar->setFormat(" %message%\n %current%/%max%\n Working on %filename%");
330+ // 100/100 -- Task is finished
0 commit comments