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

Correctly clear lines for multi-line progress bar messages#40460

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

Merged
fabpot merged 1 commit intosymfony:4.4fromgrasmash:patch-6
Mar 17, 2021

Conversation

@grasmash
Copy link
Contributor

@grasmashgrasmash commentedMar 14, 2021
edited
Loading

Measure the length of individual lines when calculating progress bar message length.

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
LicenseMIT

When a multiline message is added to a progress bar, the progress bar measures the length of all lines combined in a single string without considering whether that string contains new line characters. It is not accurately measuring the number of lines that are displayed on the terminal.

On the terminal, the actual number of new lines is dictated by a combination of new line characters and text extending beyond the terminal width. Due to this bug, the progress bar sometimes clears too many lines when the progress bar is advanced.

The progress bar should instead consider the overlap of $this->formatLineCount and the actual number of lines in the message and then add any remainder.

@carsonbotcarsonbot added this to the5.2 milestoneMar 14, 2021
@grasmashgrasmash changed the titleUpdate ProgressBar.phpMeasure the length of individual lines when calculating progress bar message length.Mar 14, 2021
@chalasr
Copy link
Member

Thanks for this. Should it be applied to 4.4 as well?
Also, can you add a test?

@grasmash
Copy link
ContributorAuthor

Yes, I’m working on a test and also trying to diagnose why the current tests are failing. But, I find that running tests while Xdebug is enableed is extremely slow with Symfony. Any tips on speeding that up?

@grasmash
Copy link
ContributorAuthor

grasmash commentedMar 14, 2021
edited
Loading

So, the test is failing because it expects:

  0/50 [>---------------------------]   0%\x1b[1A\x1b[0J  1/50 [>---------------------------]   2%\x1b[1A\x1b[0J  2/50 [=>--------------------------]   4%

But the actual is:

  0/50 [>---------------------------]   0%\x1b[2A\x1b[0J  1/50 [>---------------------------]   2%\x1b[2A\x1b[0J  2/50 [=>--------------------------]   4%

I don't really understand the difference between the\x1b[1A and\x1b[2A strings.

@grasmash
Copy link
ContributorAuthor

grasmash commentedMar 14, 2021
edited
Loading

Ok, so I did so research. This is a great article:https://notes.burke.libbey.me/ansi-escape-codes/. The 2A indicates that 2 lines should be cleared rather than 1. That seems right looking at the 3 line output in the example.

The rather unfun part of testing this is that you can't actuallysee the diff for the failing tests on the command line because they're rendered ANSI escape codes and not actually visible. Apart from using xDebug to inspect the variables (which is terribly slow) I'm not sure how one is supposed to know what's being printed.

$message_lines =explode("\n",$message);
$line_count =\count($message_lines) -$this->formatLineCount +1;
foreach ($message_linesas$message_line) {
if (Helper::strlen($message_line) /$this->terminal->getWidth() >1) {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is a second bug that's being fixed. If the Terminal width exactly matches the line length, we should not count an extra line. We should only count an extra line if it exceeds the line length.

@grasmash
Copy link
ContributorAuthor

grasmash commentedMar 14, 2021
edited
Loading

I don't believe new tests are needed. The existing test fixtures have been updated to assert that lines are emitted correctly.

Admittedly justlooking at the test fixtures doesn't grant much confidence. I performed a number of successful manual tests that used combinations of short content, long content, and content with new line characters. They all displayed as expected.

However, I'd like a functional review by someone else who is able to more readily identify issues.

@grasmash
Copy link
ContributorAuthor

@chalasr I believe this is ready to be merged. The failing tests seem unrelated to the changes made here.

@chalasr
Copy link
Member

Thank you for the detailed explanations, it makes everyone more comfortable with reviewing/merging such a patch (low-level + changes in existing tests).

Still, I'd like to checkout your branch to ensure we don't have any regression on the modified test cases (as it happened a lot in the past). I will look into this by the end of the week.

@grasmash
Copy link
ContributorAuthor

Still, I'd like to checkout your branch to ensure we don't have any regression on the modified test cases (as it happened a lot in the past). I will look into this by the end of the week.

Completely agree. 👍

@grasmash
Copy link
ContributorAuthor

grasmash commentedMar 14, 2021
edited
Loading

Separately, it looks like I should merge my approach with this proposed change:https://github.com/symfony/symfony/pull/40450/files

Done :)

@chalasr
Copy link
Member

Thanks, I was about to ask you if you could have a look at#40450 :)
Also can you rebase your PR on the 4.4 branch (+ change the base branch by editing your PR)?

@grasmash
Copy link
ContributorAuthor

I can rebase it, but I would prefer to have that in a separate pull request. Would that be OK?

@grasmash
Copy link
ContributorAuthor

Need to do some more work here to correctly integrate changes from#40450, seems to have caused a problem.

@grasmash
Copy link
ContributorAuthor

@chalasr Ok. Lot's of changes, but much better now:

  1. I've added a new test and left existing fixtures as-is.
  2. I've rebased on to 4.4 and changed the base branch for the PR.
  3. I've cherry-picked@danepowell's new test from[Console] ProgressBar clears too many lines on update #40450.

@grasmash
Copy link
ContributorAuthor

I think that all test failures are unrelated to the changes. You can see the relevant tests passing here:
https://travis-ci.com/github/symfony/symfony/jobs/491226919#L8401

@danepowell
Copy link
Contributor

As the owner of#40450, I think this approach makes sense.

@danepowell
Copy link
Contributor

danepowell commentedMar 15, 2021
edited
Loading

I guess I should say, I'd prefer for#40450 to be merged first since it addresses a separate bug and I'd love to get credit for the fix 😄 . But as long the bugs get fixed (this PR now fixes both), that's what matters most.

@grasmash
Copy link
ContributorAuthor

@danepowell I'm fine with that! Though I should say, I intentionally cherry picked your commit so you'd get commit credit if this PR is merged as is.

danepowell reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas changed the titleMeasure the length of individual lines when calculating progress bar message length.[Console] Measure the length of individual lines when calculating progress bar message lengthMar 16, 2021
@nicolas-grekas
Copy link
Member

I merged#40450 to ease with squashing this PR.

chalasr reacted with thumbs up emoji

@grasmash
Copy link
ContributorAuthor

Rebased.

@chalasr
Copy link
Member

@grasmash Can you squash your 7 commits into 1 so that we can merge?

@grasmashgrasmash changed the title[Console] Measure the length of individual lines when calculating progress bar message length[Console] Correctly clear lines for multi-line progress bar messagesMar 17, 2021
@grasmash
Copy link
ContributorAuthor

@chalasr Done!

@carsonbotcarsonbot changed the title[Console] Correctly clear lines for multi-line progress bar messagesCorrectly clear lines for multi-line progress bar messagesMar 17, 2021
@fabpot
Copy link
Member

Thank you@grasmash.

@fabpotfabpot merged commitcf79189 intosymfony:4.4Mar 17, 2021
This was referencedMar 29, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chalasrchalasrchalasr left review comments

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

6 participants

@grasmash@chalasr@danepowell@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp