@@ -175,7 +175,6 @@ current progress of the bar. Here is a list of the built-in placeholders:
175
175
* ``remaining ``: The remaining time to complete the task (not available if no max is defined);
176
176
* ``estimated ``: The estimated time to complete the task (not available if no max is defined);
177
177
* ``memory ``: The current memory usage;
178
- * ``message ``: The current message attached to the progress bar.
179
178
180
179
For instance, here is how you could set the format to be the same as the
181
180
``debug `` one::
@@ -186,20 +185,6 @@ Notice the ``:6s`` part added to some placeholders? That's how you can tweak
186
185
the appearance of the bar (formatting and alignment). The part after the colon
187
186
(``: ``) is used to set the ``sprintf `` format of the string.
188
187
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
-
203
188
Instead of setting the format for a given instance of a progress bar, you can
204
189
also define global formats::
205
190
@@ -313,25 +298,33 @@ that displays the number of remaining steps::
313
298
Custom Messages
314
299
~~~~~~~~~~~~~~~
315
300
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.
319
304
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...
323
320
324
- $bar->setMessage('Task is in progress...');
325
321
while ($file = array_pop($files)) {
326
322
$bar->setMessage($filename, 'filename');
327
323
$bar->advance();
324
+ // 2/100 -- Task is in progress... $filename
328
325
}
329
326
330
327
$bar->setMessage('Task is finished');
331
328
$bar->setMessage('', 'filename');
332
329
$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