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

[Console] Support max column width in Table#28373

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
chalasr merged 1 commit intosymfony:masterfromro0NL:console/table-width
Sep 11, 2018
Merged

[Console] Support max column width in Table#28373

chalasr merged 1 commit intosymfony:masterfromro0NL:console/table-width
Sep 11, 2018

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedSep 5, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#22156,#27832
LicenseMIT
Doc PRsymfony/symfony-docs#10300

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

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

While at it, it comes withTable integration :)

Given

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

image


$lines =array();
foreach (explode("\n",$text)as$line) {
$lines[] ='' ===$line ?$line :$this->styleStack->getCurrent()->apply($line);
Copy link
ContributorAuthor

@ro0NLro0NLSep 5, 2018
edited
Loading

Choose a reason for hiding this comment

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

here we fix#27832 by formatting each line separate. This only helps when the user wraps a string. If it's wrapped by the terminal it can still occur.

@nicolas-grekasnicolas-grekas added this to thenext milestoneSep 6, 2018
@nicolas-grekas
Copy link
Member

(tests are red)

@ro0NL
Copy link
ContributorAuthor

Ah forgot to mention; failures unrelated :)

fabbot.io is a false-positive IMHO

travis

1) Symfony\Component\Lock\Tests\Store\PdoStoreTest::testRefreshLockFailed asserting that false is true.

appveyor:

KO src\Symfony/Bundle/SecurityBundle

@nicolas-grekas
Copy link
Member

I restarted the builds on Travis and appveyor. Let's fix fabbot.

@ro0NL
Copy link
ContributorAuthor

Done. Consistent withrender() anyway and doesnt break formatting:https://api.symfony.com/3.4/Symfony/Component/Console/Helper/Table.html#method_render

if ('' !==$current &&"\n" !==substr($current, -1)) {
$text ="\n".$text;
if ($this->isDecorated()) {
foreach ($linesas &$line) {

Choose a reason for hiding this comment

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

let's not use a reference when we can do without

*
* @return $this
*/
publicfunctionsetColumnMaxWidths(array$widths):self

Choose a reason for hiding this comment

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

Do we really need this one? Can't we do the same with setColumnMaxWidth and keep a smaller public API?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

currently we havesetColumnWidth() andsetColumnWidths() to control min. width. We can do withoutsetColumnMaxWidths() but might raise some questions (why cant i set max. widths at once?)

IMHO the ideal api is:setColumnMinWidth + setColumnMaxWidth + setColumnWidth where the latter sets both min. and max. (thus fixed). However that requires to rename the currentsetColumnWidth tosetColumnMinWidth first. Not aiming for that :)

Do you suggest to dropsetColumnMaxWidths and add array support insetColumnMaxWidth or just drop it?

@ro0NL
Copy link
ContributorAuthor

Ready for me :) really happy with this feature.

Copy link
Member

@javiereguiluzjaviereguiluz left a comment

Choose a reason for hiding this comment

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

I like this! Thanks Roland.

$offset =0;
$output ='';
$tagRegex ='[a-z][a-z0-9,_=;-]*+';
$length =0;

Choose a reason for hiding this comment

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

Minor comment: should we rename$length as$maxLength ? "length" is too generic, and in this case is confusing because we are also using "width" -->$this->applyCurrentStyle(..., ..., $width, $length)

Copy link
ContributorAuthor

@ro0NLro0NLSep 10, 2018
edited
Loading

Choose a reason for hiding this comment

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

$currentLineLength? It's not a max value, e.g. for$width = 5 and$text = '123456'

12345 // $length = 0 aka "full"6     // $length = 1

So we know we can add 5-1=4 more chars before the next line break

Copy link
Member

Choose a reason for hiding this comment

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

👍 for$currentLineLength

@ro0NLro0NL mentioned this pull requestSep 11, 2018
chalasr pushed a commit that referenced this pull requestSep 11, 2018
This PR was merged into the 3.4 branch.Discussion----------[Console] Fix typo in tests| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->Spotted in#28373cc@chalasrCommits-------01e491e [Console] Fix typo in tests
@chalasr
Copy link
Member

Thank you@ro0NL.

@chalasrchalasr merged commit175f68f intosymfony:masterSep 11, 2018
chalasr pushed a commit that referenced this pull requestSep 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     <!-- seehttps://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#10300Continuation 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
@ro0NLro0NL deleted the console/table-width branchSeptember 11, 2018 17:22
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
@pjcdawkins
Copy link
Contributor

In case you're interested in an older implementation of something that sets column widths according to the terminal width:
https://github.com/platformsh/platformsh-cli/blob/281b998a369339a0e481cf450d986f03f52e2146/src/Console/AdaptiveTable.php#L12

Looks like it can now be significantly simplified based on these Console changes (thanks@ro0NL)

ro0NL and chalasr reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chalasrchalasrchalasr approved these changes

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

6 participants

@ro0NL@nicolas-grekas@chalasr@pjcdawkins@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp