New in Symfony 6.2: Console improvements

The Console component is the most downloaded non-polyfill component (+530 million downloads as of November 2022) and the component with most dependents overall (nearly 10,000 public projects depend on it). In Symfony 6.2 we added some nice new features to it.

Show Commands When Running Namespace

Contributed by
Wouter de Jong
in #47750.

When running only the namespace instead of the full command name, Symfony displays an error message:

$ bin/console debug

  Command "debug" is not defined. Did you mean one of these?
    debug:autowiring
    debug:config
    debug:container
    [...]

In Symfony 6.2 we're improving this to list instead all the commands defined under the given namespace:

$ bin/console debug
Symfony 6.2.0 (env: dev, debug: true) #StandWithUkraine https://sf.to/ukraine

Usage:
  command [options] [arguments]

  [...]

Available commands for the "debug" namespace:
  debug:autowiring        List classes/interfaces you can use for autowiring
  debug:config            Dump the current configuration for an extension
  debug:container         Display current services for an application
  debug:dotenv            Lists all dotenv files with variables and values
  debug:event-dispatcher  Display configured listeners for an application
  debug:router            Display current routes for an application

Resuming Progress Bars

Contributed by
Ivan Yivoff
in #46242.

Symfony 6.2 adds the option to resume a progress bar so it doesn't always start from 0. This is useful not only to resume long standing tasks but also to show the progress of a complex task with optional steps that can be skipped:

use Symfony\Component\Console\Helper\ProgressBar;

// create a new progress bar (length = 100 units)
$progressBar = new ProgressBar($output, 100);

// pass the new optional second argument to display the progress bar
// starting at some point different from 0 (in this example = 25)
$progressBar->start(null, 25);

Improved Color Support

Contributed by
Boudry Julien
in #46944 and #47407.

In Symfony 5.2 we introduced true colors in the console to support Ansi24 (24-bit colors) mode. In Symfony 6.2 we're improving color support by adding a new Ansi8 (256-color) mode for terminals that don't support true colors.

The best of all is that you don't have to change anything in your code. You can still use 24-bit colors and Symfony will transform them to the nearest 8-bit colors if the terminal doesn't support them (e.g. #c0392b (24-bit) is degraded to #d75f5f in 8-bit color terminals and to red in 4-bit color terminals).

Lastly, we've introduced a setColorMode(?AnsiColorMode $colorMode) method in the main Terminal class so you can force a color mode in the terminal (it overrides any env var defining the color mode).

Zsh Shell Autocompletion

Contributed by
Jitendra and Jérôme Tamarelle
in #47018.

In Symfony 5.4 we introduced console autocompletion so you can press the TAB key to see a list of contextual suggestions for commands, arguments, options, etc. Initially it only worked on Bash shells, but in Symfony 6.2 we're also adding support for Zsh shell autocompletion.

Limiting the Height of Console Sections

Contributed by
Wouter de Jong
in #47308.

Console introduced output sections in Symfony 4.1. They allow to define different output regions that you can manage independently. In Symfony 6.2 we're adding a feature to limit the height of any section:

class MyCommand extends Command
{
    // ...

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        // ...
        $debugMessages = $output->section();
        $debugMessages->setMaxHeight(3);

        // ...
    }
}

When the contents overflow the given number of rows, the new contents replace the existing contents. This is very useful to show verbose output in long running processes, without taking over the complete terminal buffer:

Console Section Height Limit

In case you missed it, your company can sponsor the Console component or any other component published by Symfony. Check out the details of our Symfony Sponsoring Program.

            <hr style="margin-bottom: 5px" />
            <div style="font-size: 90%">
                <a href="https://symfony.com/sponsor">Sponsor</a> the Symfony project.
            </div>

https://symfony.com/blog/new-in-symfony-6-2-console-improvements?utm_source=Symfony%20Blog%20Feed&utm_medium=feed

Utworzony 2y | 25 lis 2022, 09:20:07


Zaloguj się, aby dodać komentarz

Inne posty w tej grupie

New in Symfony 7.3: Extra Runtime Dot Env Files

Contributed by Nathan Page in

1 maj 2025, 08:40:12 | Symfony
SymfonyOnline June 2025: Where Have the Women of Tech History Gone?

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

30 kwi 2025, 14:20:02 | Symfony
New in Symfony 7.3: Arbitrary User Permission Checks

Contributed by Nate Wiebe in

30 kwi 2025, 09:30:12 | Symfony
SymfonyOnline June 2025: Automate Everything with Your Personal Army of Robots

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

29 kwi 2025, 15:10:03 | Symfony
New in Symfony 7.3: Slug and Twig Constraints

The Validator component provides dozens of constraints ready to use in your applications. In Symfony 7.3, we've added two new constraints to the list.

Slug Constraint

29 kwi 2025, 10:30:02 | Symfony
SymfonyOnline June 2025: Multi-Tenantize the Symfony components

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

28 kwi 2025, 15:50:10 | Symfony
New in Symfony 7.3: Twig Extension Attributes

Contributed by Jérôme Tamarelle in

28 kwi 2025, 08:50:09 | Symfony