Skip to content

[Console] added ProgressBar (to replace the stateful ProgressHelper class) #10355

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

Closed
wants to merge 1 commit into from

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Mar 1, 2014

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #9951, related to #9788
License MIT
Doc PR n/a

TODO:

  • submit a PR on the docs

This PR deprecated ProgressHelper in favor of ProgressBar. The main difference is that the new ProgressBar class is stateless, which allows for more than one bar to be displayed at a time:

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;

$output = new ConsoleOutput();

$bar1 = new ProgressBar($output, 10);
$bar2 = new ProgressBar($output, 20);
$bar2->setProgressCharacter('#');
$bar1->start();
print "\n";
$bar2->start();

for ($i = 1; $i <= 20; $i++) {
    // up one line
    $output->write("\033[1A");
    usleep(100000);
    if ($i <= 10) {
        $bar1->advance();
    }
    print "\n";
    $bar2->advance();
}

And here is how it looks like when run:

progress-bars

@fabpot
Copy link
Member Author

fabpot commented Mar 1, 2014

By the way, that also makes the progress bar part of the Console more easily reusable outside the context of a full console app/command.

@wouterj
Copy link
Member

wouterj commented Mar 1, 2014

Wouldn't it be nicer if there was a ProgressGroup or the like? There we can specify multiple progress bars and tell if it shoúld be placed horizontal or vertical. It would also handle the "moved one line up" things

/**
* Sets the progress bar width.
*
* @param int $size The progress bar size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integer for consistency

@cordoval cordoval mentioned this pull request Mar 1, 2014
1 task
@fabpot
Copy link
Member Author

fabpot commented Mar 1, 2014

I don't think it would make sense to create a ProgressGroup as it won't bring much to the table (and would restrict what you could do).

@fabpot
Copy link
Member Author

fabpot commented Mar 1, 2014

Closing for #10356 instead.

@fabpot fabpot closed this Mar 1, 2014
@fabpot fabpot deleted the progress-helper-stateless branch March 1, 2014 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants