New in Symfony 2.8: Console improvements
The Symfony Console component is our second most popular component, with more than 1 million monthly downloads and more than 2,300 projects depending on it. In Symfony 2.8 we extended its capabilities with some new features.
Allowed to apply styles to table columns¶
Contributed by
Max Grigorian
in #14044.
Symfony 2.8 allows to define a different visual style for each table column.
First, instantiate the TableStyle
class to define the style features:
1 2 3 4 | use Symfony\Component\Console\Helper\TableStyle;
$rightAligned = new TableStyle();
$rightAligned->setPadType(STR_PAD_LEFT);
|
Then, apply the custom style to any table column through its column numeric index:
1 2 3 4 5 6 7 8 9 10 | use Symfony\Component\Console\Helper\Table;
$table = new Table($output);
$table->setHeaders(['#', 'Path', 'Size']);
$table->setColumnStyle(2, $rightAligned);
// ...
$table->render();
|
Now, when rendering the table, the contents of the third column (numeric index =
2
) will be right aligned:
1 2 3 4 5 6 7 8 | +---+---------------------+---------+
| # | Path | Size |
+---+---------------------+---------+
| 1 | autoload.php | 183 |
| 2 | ApplicationTest.php | 247,794 |
| 3 | CommandTest.php | 14,965 |
| 4 | ListCommandTest.php | 2,369 |
+---+---------------------+---------+
|
Made exceptions visible in quiet mode¶
Contributed by
Jordi Boggiano
in #15772.
In some environments it's common to run console commands with the --quiet
option to avoid displaying any output. The problem is that this quiet mode also
suppress the output when an exception occurs.
In Symfony 2.8, the behavior of the "quiet verbosity mode" has changed to always display the exception details when such an error occurs. This will make your life as a developer easier and it aligns with our Developer Experience commitment.
Added a progress indicator helper¶
Contributed by
Kevin Bond
in #16409.
The progress bar helper allows to create cool animated indicators of the progress of some task. They are useful when you know beforehand when the task will finish, as in the Symfony Installer download progress bar.
However, it's common to execute tasks where you can't determine in advance when they'll be completed. That's why we've added a new progress indicator helper which displays a spinning bar while the task is running:

In addition to the spinning bar, you can output messages while the progress indicator is still active:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | use Symfony\Component\Console\Helper\ProgressIndicator;
$progress = new ProgressIndicator($output);
$progress->start('Starting...');
// do something ...
$progress->advance();
// do something ...
$progress->setMessage('Just started...');
// do something ...
$progress->setMessage('Half way...');
// do something ...
$progress->setMessage('Almost Done...');
// do something ...
$progress->finish('Done.');
|
Another nice feature of this progress indicator is that it gracefully degrades when the system doesn't support ANSI codes:

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.
New in Symfony 2.8: Console improvements symfony.com/blog/new-in-symfony-2-8-console-improvements
Tweet thisComments
Except, in the example, the third column is RIGHT aligned. The SECOND column is left aligned though... maybe the array is not zero-based?
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Oskar Stark said on Nov 13, 2015 at 12:08 #1