Skip to content

allow access/configuration to SymfonyStyle's progressBar in 7.3 #60381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tacman opened this issue May 8, 2025 · 2 comments
Open

allow access/configuration to SymfonyStyle's progressBar in 7.3 #60381

tacman opened this issue May 8, 2025 · 2 comments

Comments

@tacman
Copy link
Contributor

tacman commented May 8, 2025

Description

As I'm converting my console commands to Symfony 7.3, I've started to tighten them up by using SymfonyStyle's built-in progress bar.

But sometimes I want to customize it, or even just to access it.

Example

    public function __invoke(
        SymfonyStyle     $io,
        #[Option(description: 'batch size for flush')]
        int    $batch = 5,

Before:

         $progressBar = $io->createProgressBar($limit ?: $finder->count());
         $progressBar->start();
         foreach ($io->iterate($finder, $limit ?: $finder->count()) as $idx=>$dir) {
            $progressBar->advance();
            if (($progressBar->getProgress() % $batch) === 0) {
                $this->entityManager->flush();
                $this->entityManager->clear();
            }
          }
          $progressBar->finish(); 

After:

        foreach ($io->progressIterate($finder, $limit ?: $finder->count()) as $idx=>$dir) {
            if (($io->getProgressBar()->getProgress() % $batch) === 0) {
                $this->entityManager->flush();
                $this->entityManager->clear();
            }
    }

I'd also like to configure the progressBar verbosity independently of the command verbosity. I pretty much always want to know how much memory is being used. So maybe something like creating the progressBar and setting it in $io?

I know I can do it by simply creating a progressBar and manually calling the advance and finish, but it's less code to use the built-in one.

@javiereguiluz
Copy link
Member

We could add some options to configure some behavior of the progress bar (the verbosity example that you mentioned is a great example) but we shouldn't make the visual design of the progress bar (or any other element of SymfonyStyle) configurable.

The idea of the SymfonyStyle is that it's a set of console design tokens with an opinionated visual design. We can change the design in newer Symfony versions to tweak/fix/improve things, but users shouldn't be allowed to change the design significantly (to do so, you can use the Console helpers directly, which give you full freedom to customize the design).

@tacman
Copy link
Contributor Author

tacman commented May 10, 2025

the getProgress() is something I use a lot for batch flushing, so exposing that would be great.

I think the progressBar information should be more verbose by default. That way I'd see that memory usage was going up without having to wait for an out of memory error (and then discovering that --no-debug is critical when importing a large about of data). I can't think of a situation where I'd want to hide the memory, estimated completion time, etc.

But the getProgress is data that otherwise I'd have to track in some counter (if the iterable is not indexed-based, obviously).

Thanks for your consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants