Skip to content

[Console] Progress helper enhancements #7300

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 5 commits into from
Closed

[Console] Progress helper enhancements #7300

wants to merge 5 commits into from

Conversation

pkruithof
Copy link
Contributor

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

Two enhancements:

  1. The progress bar clears the current line before writing the current progress. This can cause some flickering in the terminal. I've modified the write method to append whitespace to the line to be written, so it matches the previous line's length.
  2. Added a setCurrent method to set the current progress. Rather than advancing by 1 or more steps, sometimes you want to just set the current state. For example if you are downloading a file, and a callback provides you with the current download status. A workaround for this could be to keep track of the previous event, calculate the difference, and advancing by the diff. But it's easier to just set the current progress.

Sidenotes:

  • The overwrite method copied documentation of the Output's write method. The difference is, the overwrite method does not handle an array of messages. I've updated the documentation for this.
  • The helper uses strlen to calculate line lengths. This could cause a problem when using multibyte strings. I'd change it to mb_strlen, but I'm not sure if the mb_string extension is required by Symfony.

@pborreli
Copy link
Contributor

pborreli commented Mar 8, 2013

did you test on Windows ?

@pkruithof
Copy link
Contributor Author

I don't have a Windows VM, is there an easy way to test on Windows?

@pborreli
Copy link
Contributor

pborreli commented Mar 8, 2013

I will test it ASAP

@pborreli
Copy link
Contributor

pborreli commented Mar 8, 2013

phpunit src\Symfony\Component\Console\Tests\Helper\ProgressHelperTest.php
PHPUnit 3.7.18 by Sebastian Bergmann.

Configuration read from C:\Users\pascal\console\symfony\phpunit.xml.dist

.........

Time: 0 seconds, Memory: 4.50Mb

OK (9 tests, 11 assertions)

@fabpot
Copy link
Member

fabpot commented Mar 8, 2013

We do not require mbstring, but we use it optionally when available. See https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Application.php#L784-L794 for instance.

public function testMultiByteSupport()
{
if (!function_exists('mb_strlen') || (false === $encoding = mb_detect_encoding('■'))) {
$this->markTestIncomplete('The mbstring extension is needed for multi-byte support');
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the test be skipped instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I'll update it.

@pkruithof
Copy link
Contributor Author

@fabpot is this good to merge? The failed Travis build seems to come from a different component.

@fabpot
Copy link
Member

fabpot commented Mar 23, 2013

I've submitted a doc change for this PR: symfony/symfony-docs#2342 and added a CHANGELOG entry

@fabpot fabpot closed this in 062cce0 Mar 23, 2013
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.

4 participants