Skip to content

Commit 4db7bab

Browse files
committed
Merge branch '4.4'
* 4.4: Document new ProgressBar time-based frequency mutators
2 parents e4ffd7b + 097b3a3 commit 4db7bab

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

components/console/helpers/progressbar.rst

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ you can also set the current progress by calling the
5050

5151
If your platform doesn't support ANSI codes, updates to the progress
5252
bar are added as new lines. To prevent the output from being flooded,
53-
adjust the
53+
use the method :method:`Symfony\\Component\\Console\\Helper\\ProgressBar::preventRedrawFasterThan`
54+
(it writes to the output after every N seconds) and the method
5455
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::setRedrawFrequency`
55-
accordingly. By default, when using a ``max``, the redraw frequency
56-
is set to *10%* of your ``max``.
56+
(it writes to the output every N iterations). By default, redraw frequency is
57+
**100ms** or **10%** of your ``max``.
58+
59+
.. versionadded::
60+
61+
The ``preventRedrawFasterThan()`` method was introduced in Symfony 4.4.
5762

5863
If you don't know the exact number of steps in advance, set it to a reasonable
5964
value and then call the ``setMaxSteps()`` method to update it as needed::
@@ -285,17 +290,20 @@ to display it can be customized::
285290

286291
.. caution::
287292

288-
For performance reasons, be careful if you set the total number of steps
289-
to a high number. For example, if you're iterating over a large number of
290-
items, consider setting the redraw frequency to a higher value by calling
291-
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::setRedrawFrequency`,
292-
so it updates on only some iterations::
293+
For performance reasons, Symfony redraws screen every 100ms. If this is too
294+
fast or to slow for your application, use these methods:
295+
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::preventRedrawFasterThan`
296+
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::setRedrawFrequency`
297+
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::forceRedrawSlowerThan`::
293298

294299
$progressBar = new ProgressBar($output, 50000);
295300
$progressBar->start();
296301

297-
// update every 100 iterations
302+
// this redraws the screen every 100 iterations, but sets additional limits:
303+
// don't redraw slower than 100ms (0.1) or faster than 200ms (0.2)
298304
$progressBar->setRedrawFrequency(100);
305+
$progressBar->forceRedrawSlowerThan(0.2);
306+
$progressBar->preventRedrawFasterThan(0.1);
299307

300308
$i = 0;
301309
while ($i++ < 50000) {
@@ -304,6 +312,11 @@ to display it can be customized::
304312
$progressBar->advance();
305313
}
306314

315+
.. versionadded::
316+
317+
The ``forceRedrawSlowerThan`` and ``preventRedrawFasterThan()`` methods
318+
were introduced in Symfony 4.4.
319+
307320
Custom Placeholders
308321
~~~~~~~~~~~~~~~~~~~
309322

0 commit comments

Comments
 (0)