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] Extract customizable BaseOutputStyle and reusable MessageBlock#42093

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

Open
hushker wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromhushker:SF-39184-symfony-style-decouple-2

Conversation

hushker
Copy link

@hushkerhushker commentedJul 13, 2021
edited by OskarStark
Loading

QA
Branch?5.4 for features
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#39184
LicenseMIT

There are two purposes of changes:

  • Make it easy to create custom Console Output Style
  • Protect SymfonyStyle style guide from overriding

Changes:

  • SymfonyStyle became the final class to prevent overriding
  • MessageBlock extracted to provide a reusable method for generating block lines
  • BaseOutputStyle extracted and could be overridden (const and methods are protected) for customization purpose

Example of customization:

<?phpnamespaceApp\OutputStyle;useSymfony\Component\Console\Formatter\OutputFormatter;useSymfony\Component\Console\Helper\Helper;useSymfony\Component\Console\Style\BaseOutputStyle;class MyCustomOutputStyleextends BaseOutputStyle{protectedconstTITLE_CHAR ='=';protectedconstSECTION_CHAR ='-';protectedconstLISTING_CHAR ='*';protectedconstCOMMENT_STYLE ='<fg=default;bg=default> // </>';protectedconstSUCCESS_STYLE ='fg=black;bg=green';protectedconstERROR_STYLE ='fg=white;bg=gray';protectedconstWARNING_STYLE ='fg=black;bg=yellow';protectedconstNOTE_STYLE ='fg=yellow';protectedconstINFO_STYLE ='fg=green';publicfunctiontitle(string$message)    {$this->autoPrependBlock();$this->writeln(['I want to customize it all',sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),sprintf('<comment>%s</>',str_repeat(static::TITLE_CHAR, Helper::width(Helper::removeDecoration($this->getFormatter(),$message)))),                       ]);$this->newLine();    }}

We can customize easily by overriding the style constants of whole methods.

@hushkerhushker requested a review fromchalasr as acode ownerJuly 13, 2021 19:17
@hushkerhushkerforce-pushed theSF-39184-symfony-style-decouple-2 branch from991fa8c to1e7a013CompareJuly 13, 2021 19:21
@hushkerhushkerforce-pushed theSF-39184-symfony-style-decouple-2 branch 2 times, most recently from14fd3a1 tob23eccaCompareJuly 13, 2021 20:39
Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

@chalasrchalasr added this to the5.4 milestoneJul 14, 2021
@hushkerhushkerforce-pushed theSF-39184-symfony-style-decouple-2 branch fromb23ecca to83c91c6CompareJuly 14, 2021 16:47
@hushkerhushkerforce-pushed theSF-39184-symfony-style-decouple-2 branch from83c91c6 toac6611aCompareJuly 14, 2021 17:51
@chalasrchalasr self-requested a reviewJuly 14, 2021 17:57
@fabpotfabpot modified the milestones:5.4,6.1Nov 3, 2021
@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.2,6.3Nov 5, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@javiereguiluzjaviereguiluzAwaiting requested review from javiereguiluz

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

[Console] Separate styling helpers out of SymfonyStyle
6 participants
@hushker@chalasr@fabpot@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp