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 formatted text cutting#22225

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/cut-format
Sep 4, 2018
Merged

[Console] Support formatted text cutting#22225

chalasr merged 1 commit intosymfony:masterfromro0NL:console/cut-format
Sep 4, 2018

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedMar 30, 2017
edited
Loading

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

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

$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

sstok reacted with thumbs up emoji
* Sets the decorated flag.
*
* @param bool $decorated Whether to decorate the messages or not
* {@inheritdoc}

Choose a reason for hiding this comment

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

does this patch apply to lower branches? if yes, should be done there

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Will look into that.

* @param string $message The message to style
*
* @return string The styled message
* {@inheritdoc}

Choose a reason for hiding this comment

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

that one is not possible: $width is not in the interface, thus should be documented here

* @return string The styled message
*/
publicfunctionformat($message);
publicfunctionformat($message/*, $width = 0*/);
Copy link
Member

@nicolas-grekasnicolas-grekasApr 3, 2017
edited
Loading

Choose a reason for hiding this comment

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

Changing an interface like that is a hard BC break. Anyone implementing it without extendingOutputFormatter will get no deprecation warning.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Any suggestions? Took this approach fromLogoutUrlGenerator::registerListener ;) which is not bound to an interface.

Note that this way is the easiest implementation and avoids double processing the formatted text, which is nice.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedApr 7, 2017
edited
Loading

Approach updated.. not sure this makes sense either :P but im concerning users extending fromOutputFormatter as well as implementingOutputFormatterInterface.

Guess i like theformat($message, $width = 0) api.. but maybe the new interface should simply definewrapAndFormat($message, $width) or so.. and letformat() forward.

fabpot added a commit that referenced this pull requestApr 10, 2017
…ro0NL)This PR was merged into the 2.7 branch.Discussion----------[Console] Inherit phpdoc from OutputFormatterInterface| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#22225 (comment)| License       | MIT| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->Commits-------ff3cb9c [Console] Inherit phpdoc from OutputFormatterInterface
@nicolas-grekasnicolas-grekas self-assigned thisAug 31, 2017
@nicolas-grekasnicolas-grekas removed their assignmentSep 16, 2017
@nicolas-grekas
Copy link
Member

Moving to 4.1. Rebase on master might be needed, where PHP 7.1 features can be used btw.

@nicolas-grekasnicolas-grekas modified the milestones:3.4,4.1Oct 8, 2017
@fabpot
Copy link
Member

@ro0NL Can you tell us the status of this PR? Looks like it should be rebased.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedMar 31, 2018
edited
Loading

@fabpot is the current upgrade path OK? If so, suggestions for namingWrappableOutputFormatterInterface welcome :)

but i was hoping we eventually dont need this interface and haveOutputInterface::format($message, $width = 0) API... but the current BC policy doesnt allow that right? Hence we're stuck with this interface.

status: needs work

if (__CLASS__ !==get_class($this)) {
$r =new \ReflectionMethod($this,__FUNCTION__);
if (__CLASS__ !==$r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method "%s()" will have a 2nd `$width = 0` argument in version 5.0. Not defining it is deprecated since 4.1.',__METHOD__),E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

... in version 5.0, not defining it is deprecated since Symfony 4.1

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you want to force people to define the$width. Not setting it explicitly seems fine to me.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Right. I should check for defined no. of arguments on the signature.

@ro0NL
Copy link
ContributorAuthor

I think the upgrade path is OK now. But i need to have a 2nd look at the fix.. cause im getting different results now as before.

@ro0NL
Copy link
ContributorAuthor

OK something spiffy is going on

image

without any src changes etc. in between.. in PHPstorm it seems to consistently format wrong.

Curious if this can be confirmed on some other terminal also.

@ro0NL
Copy link
ContributorAuthor

It seems to break as soon as it breaks out the window, thus creates a scrollbar. WTF :)

@fabpot
Copy link
Member

fabpot commentedSep 4, 2018
edited
Loading

@ro0NL What do we do here? Any ideas how to move forward?

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedSep 4, 2018
edited
Loading

@fabpot rebased. The breaking format is unrelated (#27832), so if tests are still passing im 👍 to merge. But let me add some rendering tests tomorrow.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedSep 4, 2018
edited
Loading

And perhaps rethinkWrappableOutputFormatterInterface, overriding the definition ofOutputFormatterInterface::format().

Perhaps more explicitWrappableOutputFormatterInterface::formatAndWrap(string $message, int $width) and let the implementation forward toformat($message, $width), whereOutputFormatter::format() still supports the 2nd arg, but not as part of the interface..

Then again, currently it allows to updateOutputFormatterInterface::format() with the 2nd arg in 5.0 IIUC

@ro0NL
Copy link
ContributorAuthor

Updated. Much cleaner IMHO.

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

Looks much better to me

@chalasr
Copy link
Member

chalasr commentedSep 4, 2018
edited
Loading

Nice one! Thanks Roland.

@chalasrchalasr merged commit09f8ad9 intosymfony:masterSep 4, 2018
chalasr pushed a commit that referenced this pull requestSep 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
@ro0NLro0NL deleted the console/cut-format branchSeptember 5, 2018 05:58
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
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas requested changes

@fabpotfabpotfabpot approved these changes

@chalasrchalasrchalasr approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

5 participants

@ro0NL@nicolas-grekas@fabpot@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp