Progressbar component displayed on multiple lines in symfony

I use in a simple command task with Symfony2 (2.6.6).

My code looks like this:

... $progress = new ProgressBar($output, $total); $progress->start(); if (($handler = fopen($file, "r")) !== FALSE) { while (($row = fgetcsv($handler, 1000, ",")) !== FALSE) { $this->whatever(); $progress->advance(); } fclose($handler); $progress->finish(); } ... 

And the result is as follows:

  0/50 [>---------------------------] 0% 5/50 [==>-------------------------] 10% 10/50 [=====>----------------------] 20% 15/50 [========>-------------------] 30% 20/50 [===========>----------------] 40% 25/50 [==============>-------------] 50% 30/50 [================>-----------] 60% 35/50 [===================>--------] 70% 40/50 [======================>-----] 80% 45/50 [=========================>--] 90% 50/50 [============================] 100 

The progress bar does not restart, appears in a new line with each ->advance() . I am sure that the function ->whatever(); does nothing with the exit.

Does anyone know why this behavior? Thank you!

sorry for my English

+6
source share
3 answers

You can use setOverwrite() when initializing the progress bar:

 $progress = new ProgressBar($output, $total); $progress->setOverwrite(true); $progress->start(); ... 

This determines whether to overwrite the progress bar or create a new line. http://api.symfony.com/3.0/Symfony/Component/Console/Helper/ProgressBar.html#method_setOverwrite

+3
source

You prefer to use the SymfonyStyle class (sf> = 2.7) since the console assistant is now deprecated.

Here is a dummy example:

 protected function execute(InputInterface $input, OutputInterface $output) { $console = new SymfonyStyle($input, $output); $console->title('Dummy progressBar example'); $console->progressStart(100); for ($i = 0; $i < 100; $i++) { // do something sleep(1); $console->progressAdvance(); } $console->progressFinish(); // force progress $console->success('Dummy progressBar example complete!'); } 
0
source

you can try $ output-> setDecorated (true);

-1
source

Source: https://habr.com/ru/post/985357/


All Articles