New in Symfony 7.2: Console Finished Indicator
November 7, 2024 • Published by Javier Eguiluz
Symfony 7.2 is backed by:
The Symfony Console component has become the standard way of creating CLI commands and applications in PHP. More than 11,000 open source projects use it, and it's close to 1 billion downloads since it was released in October 2011.
Rock-solid and mature components like this no longer add revolutionary new features, but in each Symfony version, we improve it with small quality-of-life and DX (developer experience) tweaks.
In Symfony 7.2, we improved the Console component to allow you to customize the finished indicator. When using a progress indicator to let the user know that the component is not stalled, by default, you see a rotating text spinner:
You can customize the progress indicator with your own spinner or animation. The main issue is that when the command finishes, it displays the last progress indicator used, which can vary each time you run the command. This inconsistency in the final result is often less than ideal.
In Symfony 7.2 we're improving this by showing ✔ as the finished indicator:
You can fully customize this value with the new finishedIndicatorValue
option.
For example, you could show a different indicator based on the result of the command:
1 2 3 4 5 6 7 8 9 10 11
use Symfony\Component\Console\Helper\ProgressIndicator;
// ...
$progressIndicator = new ProgressIndicator($output, finishedIndicatorValue: '✅');
try {
/* do some work here ... */
$progressIndicator->finish('Finished');
} catch (\Exception) {
$progressIndicator->finish('Failed', '🚨');
}
And this is how it looks when the command runs successfully:
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Nice addition! I do think that the code example
finishedIndicatorValue
does not match with what is shown in the animation below.Great! 👍🏻
@Bob you are right! I just fixed this mistake. Thanks.
Yay that's indeed much better, before I was always wondering if my terminal didn't just freeze when my command finished 😅
The progressIndicator needs to start first, otherwise it throws an error:
Something like:
@Tac you are right. In order to simplify the code example, I put that under the section with the comment:
/* do some work here ... */
In the Symfony Docs you can find the full working example. Thanks.