Skip to content

[Console] Fix bar width with multilines ProgressBar's format #21958

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

Conversation

maidmaid
Copy link
Contributor

@maidmaid maidmaid commented Mar 10, 2017

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

The bar width is badly recalculated when we use multilines (\n) and bar placeholer (%bar%) in ProgressBar's format. The bar width is reduced because multilines is considered as a big oneline. This PR fixes this.

nicolas-grekas
nicolas-grekas previously approved these changes Mar 15, 2017
@nicolas-grekas
Copy link
Member

I guess needs to merged in a lower branch thought

@maidmaid
Copy link
Contributor Author

Should I rebase the PR @nicolas-grekas?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 15, 2017

If you don't mind, please do, and change the base branch here yes.
Otherwise, we can do that while merging (and target 2.7 isn'it?)

@maidmaid
Copy link
Contributor Author

Rebase onto 2.7 has some conflicts. Create a new PR on 2.7 seems a better idea.

@nicolas-grekas
Copy link
Member

OK for me

@maidmaid
Copy link
Contributor Author

Fix this onto 2.7 takes more time than expected. Could you merge this PR and later I will create new PR for 2.7?

@fabpot
Copy link
Member

fabpot commented Mar 15, 2017

We only merge fixes in the lowest maintained branch (we don't backport fixes).

@maidmaid
Copy link
Contributor Author

Ok, so I will create new PR on 2.7 an other time.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Mar 17, 2017
@nicolas-grekas nicolas-grekas dismissed their stale review March 17, 2017 12:12

to be rebased on 2.7

@maidmaid
Copy link
Contributor Author

In fact, the resizing of ProgressBar appears from 3.2 and not before. So, I propose to rebase on 3.2.

@nicolas-grekas
Copy link
Member

Let's go for 3.2.

$lineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line);
// gets string length for each sub line with multiline format
$linesLength = array_map(function ($subLine) {
return Helper::strlenWithoutDecoration($this->output->getFormatter(), $subLine);
Copy link
Member

Choose a reason for hiding this comment

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

rtrim($subLine, "\r") to handle "\r\n" line endings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AppVeyor tests are broken because of this?

return Helper::strlenWithoutDecoration($this->output->getFormatter(), $subLine);
}, explode("\n", $line));

$maxLineLength = max($linesLength);
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest renaming maxLineLength to linesWidth

@maidmaid maidmaid changed the base branch from master to 3.2 March 20, 2017 14:24
@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

Apparently, tests are still broken on Windows

@maidmaid maidmaid force-pushed the fixprogressbar branch 2 times, most recently from 33029b4 to 8349d1d Compare March 23, 2017 12:00
@maidmaid
Copy link
Contributor Author

Need some help to fix tests please.


public function testBarWidthWithMultilineFormat()
{
putenv('COLUMNS=10');
Copy link
Member

@stof stof Mar 30, 2017

Choose a reason for hiding this comment

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

this must be reset at the end of the test to avoid affecting other tests (including when the test fails, so use try/finally)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @stof, I will check that.

@maidmaid
Copy link
Contributor Author

Tests are now green :)

@nicolas-grekas nicolas-grekas self-requested a review April 17, 2017 20:01
@maidmaid
Copy link
Contributor Author

PR ready.

@fabpot
Copy link
Member

fabpot commented Apr 25, 2017

Thank you @maidmaid.

fabpot added a commit that referenced this pull request Apr 25, 2017
…at (maidmaid)

This PR was squashed before being merged into the 3.2 branch (closes #21958).

Discussion
----------

[Console] Fix bar width with multilines ProgressBar's format

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

The bar width is badly recalculated when we use multilines (``\n``) and bar placeholer (``%bar%``) in ProgressBar's format. The bar width is reduced because multilines is considered as a big oneline. This PR fixes this.

Commits
-------

3d58ab5 [Console] Fix bar width with multilines ProgressBar's format
@fabpot fabpot closed this Apr 25, 2017
@maidmaid maidmaid deleted the fixprogressbar branch April 25, 2017 15:10
@fabpot fabpot mentioned this pull request May 1, 2017
@maidmaid maidmaid restored the fixprogressbar branch May 19, 2017 13:48
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.

5 participants