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

Skip to content

[Console] Format unset codes break with scrollbar #27832

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
ro0NL opened this issue Jul 3, 2018 · 0 comments
Closed

[Console] Format unset codes break with scrollbar #27832

ro0NL opened this issue Jul 3, 2018 · 0 comments

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Jul 3, 2018

Symfony version(s) affected: 4.1, probably lower as well

Description

When working on #22225, i noticed something goes wrong with the CLI unset codes as soon a formatted text spans multiple lines, and the output exceeds the window ($LINES), thus when the scrollbar becomes active.

See #22225 (comment)

How to reproduce

My console window ($LINES x $COLUMNS) is set to 12 x 72

I quickly patched the AboutCommand as follow:

diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
index b6860a2..973c1e1 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
@@ -56,6 +56,9 @@ EOT
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
+        $output->writeln(str_repeat("pre <error>foo bar baz</error> post", 15));
+        return 0;
+
         $io = new SymfonyStyle($input, $output);

Now running it during 1 session (my scrollbar is invisible here btw 😅)

1st 👍

image

2nd 👍

image

3rd 👎

image

Possible Solution
Not sure, I hope someone can explain what's happening technically.

Additional context

return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));

chalasr pushed a commit that referenced this issue Sep 11, 2018
This PR was squashed before being merged into the 4.2-dev branch (closes #28373).

Discussion
----------

[Console] Support max column width in Table

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #22156, #27832
| License       | MIT
| Doc PR        | symfony/symfony-docs#10300

Continuation of #22225 to better preserve spaces (which preserves background colors), using `wordwrap` it caused some issues.

Also the wrapping was plain wrong by not taking the current line length into account.

While at it, it comes with `Table` integration :)

Given

```php
$table = new Table($output);
$table->setColumnMaxWidth(0, 2);
$table->setRow(0, ['pre <error>foo bar baz</error> post']);
$table->render();

$table = new Table($output);
$table->setColumnMaxWidth(0, 3);
$table->setRow(0, ['pre <error>foo bar baz</error> post']);
$table->render();

$table = new Table($output);
$table->setColumnMaxWidth(0, 4);
$table->setRow(0, ['pre <error>foo bar baz</error> post']);
$table->render();
```

![image](https://user-images.githubusercontent.com/1047696/45101516-f19b5880-b12b-11e8-825f-6a1d84f68f47.png)

Commits
-------

175f68f [Console] Support max column width in Table
@ro0NL ro0NL closed this as completed Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants