-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add progress indicator helper #12119
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
Conversation
It could be helpfull |
@kbond Still willing to finish this one? I think this is indeed a good idea. |
@fabpot sure, I rebased and fixed some CS issues. One thing I noticed with the animation is it sometimes looks strange - you can see it in the above gif after the "Half way..." message it just alternates between Anyway, anything that needs to be changed/fixed, let me know. |
Tests fail on Windows: https://ci.appveyor.com/project/fabpot/symfony/build/1.0.846/job/vcf2cxf0l2wxw52s#L550 , could you help with that? |
It can't be from the PR - I haven't added any tests yet. |
@kbond Can you add some tests? |
@fabpot added. |
I rebased to master. The console component's tests are failing but is unrelated to this PR. |
$this->indicatorCurrent = 0; | ||
} else { | ||
++$this->indicatorCurrent; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just do a simple incrementation here (++$this->indicatorCurrent;
), and then use a modulo where it is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
I added a speed trap so the indicator doesn't change more than once per 100 (default) milliseconds. |
*/ | ||
public function getStartTime() | ||
{ | ||
return $this->startTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start time can probably be removed altogether as it's not used anywhere. It's useful in the progress bar as we display time information, but as this is not the case here, I don't see how it can be useful. Or would it be useful to add the possibility to add the elapsed time in the format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind.
To make the indicator immutable, should I remove some public setters? |
👍 for making it immutable; if the list of arguments on the constructor is too large, you can also keep the setter but throw an exception when used after the indicator is started. |
I agree with @fabpot. changing the display in the middle does not make much sense to me (and could even cause issues). |
Ok, I made it immutable and ensured it can be used multiple times per instance. Unless there are any other changes, this is good to go. |
* Gets the current indicator message. | ||
* | ||
* @return string|null | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is also internal, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just getMessage
- I will mark as such. Unless you want me to remove setMessage and just use advance
to set a new message.
👍 |
@kbond Looks like the tests on Windows do not pass. |
Damn, ok I will have a look. It's hard to see what the problem is from the output. |
Tests on Windows are passing now! |
Thank you @kbond. |
This PR was squashed before being merged into the 3.0-dev branch (closes #12119). Discussion ---------- [Console] Add progress indicator helper | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | *todo* This is an alternative to the `ProgressBar` helper *without a max* inspired by the `npm` cli. You can use the `ProgressBar` but IMO it doesn't look great or fallback nicely in non-ansi environments. A lot of work needs to be done still but thought I would get some comments on this idea. ##### Example code ```php $progress = new ProgressIndicator($output); $progress->start('Starting...'); for ($i = 0; $i < 100; $i++) { usleep(25000); $progress->advance(); switch ($i) { case 20: $progress->setMessage('Just started...'); break; case 50: $progress->setMessage('Half way...'); break; case 90: $progress->setMessage('Almost Done...'); break; } } $progress->finish('Done.'); ``` ##### Screenshot  Commits ------- abf389c [Console] Add progress indicator helper
I noticed this was merged into 3.0 but not 2.8 - I thought 3.0 was not getting any new features that are not in 2.8. |
This PR was merged into the 2.8 branch. Discussion ---------- [Console] Add progress indicator helper | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12119 | License | MIT | Doc PR | Commits ------- be0a364 [Console] Add progress indicator helper
This is an alternative to the
ProgressBar
helper without a max inspired by thenpm
cli. You can use theProgressBar
but IMO it doesn't look great or fallback nicely in non-ansi environments.A lot of work needs to be done still but thought I would get some comments on this idea.
Example code
Screenshot