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

Skip to content

[Console] use ANSI escape sequences in ProgressBar overwrite method #18496

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 2 commits into from

Conversation

alekitto
Copy link
Contributor

@alekitto alekitto commented Apr 9, 2016

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? maybe
Deprecations? no
Tests pass? yes
Fixed tickets #16957
License MIT
Doc PR

Rewritten overwrite method in ProgressBar class to use ANSI escape sequences to erase lines.
This removes the need to store the last message length as it is not needed to fill the buffer with spaces anymore. As a plus it correctly resets the cursor position while clearing the output

If the output is not decorated the behavior has not been changed.
Could possibly cause a BC break if testing against the decorated emitted output as binary string

@fabpot
Copy link
Member

fabpot commented Apr 11, 2016

👍

1 similar comment
@xabbuh
Copy link
Member

xabbuh commented Apr 14, 2016

👍

@javiereguiluz
Copy link
Member

ANSI codes are very "unreadable". So, what do you think changing code like this:

// Erase the line
$this->output->write("\x1B[2K");

By something like this?

$eraseLineCode = "\x1B[2K";

// ...

$this->output->write($eraseLineCode);

Or:

$ansiCodes = array(
    'eraseLine' => "\x1B[2K"
);

// ...

$this->output->write($ansiCodes['eraseLine']);

Maybe in a separate PR?

@alekitto
Copy link
Contributor Author

We can write them as class constants, but what do you think about implementing a class to build escape sequences?

@fabpot
Copy link
Member

fabpot commented Apr 14, 2016

@alekitto Probably a very good idea but out of the scope of this PR.

@fabpot
Copy link
Member

fabpot commented Apr 14, 2016

Thank you @alekitto.

fabpot added a commit that referenced this pull request Apr 14, 2016
…te method (alekitto)

This PR was squashed before being merged into the 2.7 branch (closes #18496).

Discussion
----------

[Console] use ANSI escape sequences in ProgressBar overwrite method

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

Rewritten `overwrite` method in ProgressBar class to use ANSI escape sequences to erase lines.
This removes the need to store the last message length as it is not needed to fill the buffer with spaces anymore. As a plus it correctly resets the cursor position while clearing the output

If the output is not decorated the behavior has not been changed.
Could possibly cause a BC break if testing against the decorated emitted output as binary string

Commits
-------

b6cca4c [Console] use ANSI escape sequences in ProgressBar overwrite method
@fabpot fabpot closed this Apr 14, 2016
@alekitto
Copy link
Contributor Author

@fabpot Great! I'll open a new PR against the master branch for the escape sequences builder

@javiereguiluz
Copy link
Member

@alekitto please before sending a PR, open an issue to discuss about it. A "escape sequence builder" sounds too complex for this simple problem. Thanks!

This was referenced Apr 29, 2016
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