Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] progress bar fix #19012

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

Merged
merged 5 commits into from
Jun 17, 2016
Merged

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Jun 9, 2016

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

This is #16490 where I've simplified the code as much as possible and added a test for the bug we're trying to fix.

The main change is the renaming of the TerminalDimensionsProvider to just Terminal. The new class can probably be useful to add more about the terminal.

@stof
Copy link
Member

stof commented Jun 9, 2016

There is still 1 drawback here: as the ProgressBar uses its own Terminal instance, it will ignore any explicit overwrite done in the Application.

@stof
Copy link
Member

stof commented Jun 9, 2016

do you want to merge this in 3.2 only or in older branches as a bugfix ?

@fabpot
Copy link
Member Author

fabpot commented Jun 9, 2016

I'm aware of the drawback. I don't see how to fix this and TBH, I don't think it matters too much as playing with the dimensions should only be done when testing an app.

Only for 3.2.

@fabpot
Copy link
Member Author

fabpot commented Jun 9, 2016

Added some deprecations now.

*/
protected function getTerminalWidth()
{
$dimensions = $this->getTerminalDimensions();

return $dimensions[0];
Copy link
Member

Choose a reason for hiding this comment

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

please add the deprecation warnings too

@javiereguiluz
Copy link
Member

The new Symfony\Component\Console\Terminal class is missing in the PR.

@fabpot fabpot force-pushed the console-progress-bar-fix branch 5 times, most recently from a095d0b to 8d71aff Compare June 9, 2016 15:41
@fabpot
Copy link
Member Author

fabpot commented Jun 9, 2016

added the deprecations and simplified the code again by removing getDimensions().

@fabpot fabpot force-pushed the console-progress-bar-fix branch 3 times, most recently from 9773191 to 5afbdbb Compare June 9, 2016 16:03
/**
* Sets the terminal height.
*
* @param int
Copy link
Member

Choose a reason for hiding this comment

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

missing param name, makign the phpdoc invalid

@fabpot fabpot force-pushed the console-progress-bar-fix branch 2 times, most recently from 60a2d62 to a38bb97 Compare June 9, 2016 16:26
@nicolas-grekas
Copy link
Member

It could be useful to configure width+height with an env var, especially in tests.
This would allow testing commands that hardcode new SymfonyStyle and would replace the stty cols 120 in the .travis.yml file (and could replace the getTerminal extension points and replace related mocks).

@fabpot
Copy link
Member Author

fabpot commented Jun 10, 2016

@nicolas-grekas Done. I've kept the config in .travis.yml

@nicolas-grekas
Copy link
Member

LGTM, except a test failure

$this->terminalDimensions = array($width, $height);
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Set the ANSICON env var instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);

putenv('ANSICON='.$width.'x'.$height);
Copy link
Member

Choose a reason for hiding this comment

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

this is a bad idea, as it will also impact the detection of color support on Windows

Copy link
Member

Choose a reason for hiding this comment

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

We should support a different env var following the same format if we want to go this way (but keeping support for the ANSICON one for auto-detection)

Copy link
Member

Choose a reason for hiding this comment

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

btw, this code is broken, as it does not invalidate the Terminal cache

Copy link
Member

Choose a reason for hiding this comment

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

What about using COLUMNS and LINES? These are what bash uses (they are magic variables that can be overriden, try echo $COLUMNS).

@fabpot fabpot force-pushed the console-progress-bar-fix branch from 6e105a8 to 2eeb7bd Compare June 13, 2016 19:50
@fabpot fabpot force-pushed the console-progress-bar-fix branch 2 times, most recently from 534d825 to c92b2b4 Compare June 16, 2016 13:11
@fabpot
Copy link
Member Author

fabpot commented Jun 16, 2016

Broken test on HHVM not related.

@nicolas-grekas
Copy link
Member

👍 with this patch:

--- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php
+++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php
@@ -28,6 +28,8 @@ class UserPasswordEncoderCommandTest extends WebTestCase

    public function testEncodePasswordEmptySalt()
    {
+        putenv('COLUMNS=120');
+
        $this->passwordEncoderCommandTester->execute(array(
            'command' => 'security:encode-password',

@stof
Copy link
Member

stof commented Jun 16, 2016

@fabpot are you sure ? the failing test is related to line wrapping in commands.

I think one of your Console test does not properly reset the env variables on teardown, and so it impacts subsequent tests. Non-hhvm builds are unaffected because they use a separate PHP process per component to run things in parallel

@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Set the COLUMNS and LINES env vars instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);

putenv('COLUMNS='.$width);
putenv('LINES='.$height);
Copy link
Member

Choose a reason for hiding this comment

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

this does not work in case the dimensions were already retrieved previously, because of the Terminal internal cache

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@fabpot fabpot force-pushed the console-progress-bar-fix branch 4 times, most recently from 660b6e8 to b233974 Compare June 16, 2016 15:54
@fabpot
Copy link
Member Author

fabpot commented Jun 16, 2016

should be good now :)

@fabpot fabpot force-pushed the console-progress-bar-fix branch from b233974 to 355ad6c Compare June 16, 2016 16:11
}
}

if (0 === self::$width) {
Copy link
Member

Choose a reason for hiding this comment

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

not sure this check works: when is this zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

that's old code, removed.

@fabpot fabpot force-pushed the console-progress-bar-fix branch from 355ad6c to dba73e7 Compare June 17, 2016 07:00
@fabpot fabpot force-pushed the console-progress-bar-fix branch from dba73e7 to 2f81247 Compare June 17, 2016 17:36
@fabpot
Copy link
Member Author

fabpot commented Jun 17, 2016

Thank you @TomasVotruba.

@fabpot fabpot merged commit 2f81247 into symfony:master Jun 17, 2016
fabpot added a commit that referenced this pull request Jun 17, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Console] progress bar fix

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

This is #16490 where I've simplified the code as much as possible and added a test for the bug we're trying to fix.

The main change is the renaming of the `TerminalDimensionsProvider` to just `Terminal`. The new class can probably be useful to add more about the terminal.

Commits
-------

2f81247 switched to use COLUMNS and LINES env vars to change terminal dimensions
bf7a5c5 fixed logic
a589635 deprecated some Console Application methods
8f206c8 fixed CS, simplified code
b030c24 [Console] ProgressBar - adjust to the window width (static)
@TomasVotruba
Copy link
Contributor

Thank you @fabpot for finishing!

@fabpot fabpot mentioned this pull request Oct 27, 2016
nicolas-grekas added a commit that referenced this pull request May 21, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

[Console] Remove deprecated features

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~~#18999 #19012~~
| License       | MIT
| Doc PR        | n/a

Commits
-------

4cde3b9 [Console] Remove deprecated features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants