Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Added support for labels to ProgressHelper#10187

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

JustAdam
Copy link

Allows the addition of a label to the progress helper. For long(er) running tasks it could be nice to provide some additional information on what is currently happening in textual form.

$progress = $this->getHelperSet()->get('progress');$progress->setLabel('Starting download', $progress::LABEL_BOTTOM, $progress::LABEL_CENTER);$progress->start($output, $end);$progress->display();for ($i = 0; $i < $end; $i++) {    $x = $i + 1;    $progress->updateLabel('Downloading ' . $x);    $progress->advance();    sleep(1);}$progress->finish();

The label can be position above or under the progress bar, and left/center/right aligned. To allow for positioning over the progress bar, I had to move the line length padding code from overwrite() to display().

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

* @param int $position Where to show the label
* @param int $align How to align the label
*/
public function addLabel($label, $position = self::LABEL_BOTTOM, $align = self::LABEL_CENTER)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it besetLabel() because there can only one and it will be overridden on each call? Add sounds like you could add another label with each call..

Copy link
Author

Choose a reason for hiding this comment

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

Agreed; unless anyone can see a need for adding more than one label (one over and one under). Probably not .. :-)

@GromNaN
Copy link
Member

Can you give an example of the different positions ?

@staabm
Copy link
Contributor

See unit tests

@fabpotfabpot mentioned this pull requestMar 1, 2014
1 task
@fabpot
Copy link
Member

Closing in favor of#10356

@fabpotfabpot closed thisMar 1, 2014
fabpot added a commit that referenced this pull requestMar 3, 2014
This PR was merged into the 2.5-dev branch.Discussion----------[Console] A better progress bar| Q             | A| ------------- | ---| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#9573,#9574,#10187,#9951, related to#9788| License       | MIT| Doc PR        |symfony/symfony-docs#3626TODO: - [x] add some docsSee what this PR allows you to do easily:![cwzpvk](https://f.cloud.github.com/assets/47313/2302190/30cd80e4-a170-11e3-8d88-80c4e4ca8b23.gif)## New ProgressBar classFirst, this PR deprecates `ProgressHelper` in favor of `ProgressBar`. The main difference is that the new `ProgressBar` class represents a single progress bar, which allows for more than one bar to be displayed at a time:```phpuse 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](https://f.cloud.github.com/assets/47313/2300612/4465889a-a0fd-11e3-8bc2-b1d2a0f5dc3d.gif)## Format PlaceholdersThis pull request refactors the way placeholders in the progress bar are managed. It is now possible to add new placeholders or replace existing ones:```php// set a new placeholderProgressBar::setPlaceholderFormatterDefinition('remaining_steps', function (ProgressBar $bar) {    return $bar->getMaxSteps() - $bar->getStep();});// change the behavior of an existing placeholderProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {    return $bar->getMaxSteps() ?: '~';});```Several new built-in placeholders have also been added: * `%remaining%`: Display the remaining time * `%estimated%`: Display the estimated time of the whole "task" * `%memory%`: Display the memory usage## FormatsFormats can also be added (or built-in ones modified):```phpProgressBar::setFormatDefinition('simple', '%current%');$bar->setFormat('simple');// is equivalent to$bar->setFormat('%current%');```Built-in formats are: * `quiet` * `normal` * `verbose` * `quiet_nomax` * `normal_nomax` * `verbose_nomax`## Format MessagesYou can also set arbitrary messages that depends on the progression in the progress bar:```php$bar = new ProgressBar($output, 10);$bar->setFormat("%message% %current%/%max% [%bar%]");$bar->setMessage('started');$bar->start();$bar->setMessage('advancing');$bar->advance();$bar->setMessage('finish');$bar->finish();```You are not limited to a single message (`message` being just the default one):```php$bar = new ProgressBar($output, 10);$bar->setFormat("%message% %current%/%max% [%bar%] %end%");$bar->setMessage('started');$bar->setMessage('', 'end');$bar->start();$bar->setMessage('advancing');$bar->advance();$bar->setMessage('finish');$bar->setMessage('ended...', 'end');$bar->finish();```## Multiline FormatsA progress bar can now span more than one line:```php$bar->setFormat("%current%/%max% [%bar%]\n%message%");```## Flexible Format DefinitionsThe hardcoded formatting for some placeholders (like `%percent%` or `%elapsed%`) have been removed in favor of a `sprintf`-like format:```php$bar->setFormat("%current%/%max% [%bar%] %percent:3s%");```Notice the `%percent:3s%` placeholder. Here, `%3s` is going to be used when rendering the placeholder.## ANSI colors and EmojisThe new progress bar output can now contain ANSI colors and.or Emojis (see the small video at the top of this PR).Commits-------0d1a58c [Console] made formats even more flexible8c0022b [Console] fixed progress bar when using ANSI colors and Emojis38f7a6f [Console] fixed PHP comptability244d3b8 [Console] added a way to globally add a progress bar format or modify a built-in onea9d47eb [Console] added a way to add a custom message on a progress bar7a30e50 [Console] added support for multiline formats in ProgressBar1aa7b8c [Console] added more default placeholder formatters for the progress bar2a78a09 [Console] refactored the progress bar to allow placeholder to be extensible4e76aa3 [Console] added ProgressBar (to replace the stateful ProgressHelper class)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@JustAdam@GromNaN@staabm@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp