8000 [Console] Table width does not take paddings into account / lacks cell wrapping · Issue #22156 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Table width does not take paddings into account / lacks cell wrapping #22156

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 Mar 25, 2017 · 1 comment
Closed

Comments

@ro0NL
Copy link
Contributor
ro0NL commented Mar 25, 2017
Q A
Bug report? no
Feature request? yes
Symfony version master

Given

dump('benchmark');
$output->writeln(str_repeat('-', getenv('COLUMNS')));

dump('table short; min width');
$table = new Table($output);
$table->setRows(array(
    array(implode(', ', range('A', 'Z'))),
));
$table->setColumnWidths(array(getenv('COLUMNS')));
$table->render();

dump('table long; default width');
$table = new Table($output);
$table->setRows(array(
    array(implode(', ', range('1', '100'))),
));
$table->render();

It renders

image

For the min-width example i expected a perfectly fitting table :)

The default-width example works as documented, and setColumnWidth wont help, because that's actually setMinColumnWidth (also documented i believe :))

Imo. we're missing a setMaxColumnWidth or something to control text wrapping. Im not sure we should ever exceed the max. (terminal) width unless we cant wrap any further of course.

Any thoughts?

@ro0NL
Copy link
Contributor Author
ro0NL commented Mar 26, 2017 8000

setColumnWidth technically works correct, i dont think we should change anything there. What we do miss (imo.) is a setMaxColumnWidth, setWidth and setMaxWidth.

The latter 2 define the total table width, and can pre-calculate proper column widths.

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

Discussion
----------

[Console] Support formatted text cutting

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes/no
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

allows cutting a formatted text to a certain width. Actually needed if we want to support max. column widths in tables (see #22156)

```php
$text = 'pre <error>foo bar baz</error> post';
dump('BEFORE');
$output->writeln(wordwrap($output->getFormatter()->format($text), 3, "\n", true), OutputInterface::OUTPUT_RAW);
dump('AFTER');
$output->writeln($output->getFormatter()->format($text, 3), OutputInterface::OUTPUT_RAW);
```
![image](https://cloud.githubusercontent.com/assets/1047696/24519346/19c9b0ca-1585-11e7-8437-0bcfb6fab63e.png)

Commits
-------

09f8ad9 [Console] Support formatted text cutting
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
0