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] Terminal Color Mode refactoring and force Color Mode#47407

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
fabpot merged 1 commit intosymfony:6.2fromjulien-boudry:arcenciel2
Sep 7, 2022

Conversation

@julien-boudry
Copy link
Contributor

QA
Branch?6.2 for features
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT

Continue#46944

Terminal Color Mode refactoring: Adding a way to force color mode by the dev. user (with a new method), fewergetenv() calls (cache value), simpler tests (use the a new method and a new constant).

For example, it can be useful in an environment where none of the expected environment variables are available (Docker container...) , but where the support of a specific mode is imperative.

A future evolution could be to add an optional default option to all commands to force a particular mode by the final user.

@julien-boudryjulien-boudryforce-pushed thearcenciel2 branch 2 times, most recently frome851fd9 tod430f59CompareAugust 27, 2022 14:17
@julien-boudry
Copy link
ContributorAuthor

julien-boudry commentedAug 27, 2022
edited
Loading

Do you prefer as actually:

Terminal::getTermColorMode();Terminal::setTermColorMode();(private) Terminal::$termColorMode;

Or?

Terminal::getColorMode();Terminal::setColorMode();(private) Terminal::$colorMode;

@alamirault
Copy link
Contributor

Do you prefer as actually:

Terminal::getTermColorMode();Terminal::setTermColorMode();(private) Terminal::$termColorMode;

Or?

Terminal::getColorMode();Terminal::setColorMode();(private) Terminal::$colorMode;

I preferTerminal::getColorMode();

…r mode by user, fewer getenv() calls, simpler tests.It can be useful for example in the case of an environment where none of the expected environment variables are available (Docker container...) , but where the support of a specific mode is imperative.
@julien-boudry
Copy link
ContributorAuthor

I agree. I just push a new version with just theses naming changes.
For me, it's ready to merge.

@julien-boudry
Copy link
ContributorAuthor

julien-boudry commentedSep 7, 2022
edited
Loading

About Psalm, which triggers some erros here. They are all false positives, because it is in fact impossible. The case is handled upstream in the getColorMode method, but Psalm is not smart enough for that.

There is - I think - only one way to deal with it:

  • Add a static method like resetColorMode(): void {self::$colorMode = null;}
  • Disallow null values as arguments toTerminal::setColorMode(AnsiColorMode $colorMode) instead ofTerminal::setColorMode(?AnsiColorMode $colorMode).

However, this is an unnecessary burden on the public API to please psalm, when the code looks clean and logical to me.

Original Psalm log, actually:

Error: src/Symfony/Component/Console/Terminal.php:29:44: InvalidNullableReturnType: The declaredreturntype'Symfony\Component\Console\Output\AnsiColorMode'for Symfony\Component\Console\Terminal::getColorMode is not nullable, but'Symfony\Component\Console\Output\AnsiColorMode|null' contains null (see https://psalm.dev/144)Error: src/Symfony/Component/Console/Terminal.php:43:24: NullableReturnStatement: The declaredreturntype'Symfony\Component\Console\Output\AnsiColorMode'for Symfony\Component\Console\Terminal::getColorMode is not nullable, but thefunctionreturns'null' (see https://psalm.dev/139)Error: src/Symfony/Component/Console/Terminal.php:49:24: NullableReturnStatement: The declaredreturntype'Symfony\Component\Console\Output\AnsiColorMode'for Symfony\Component\Console\Terminal::getColorMode is not nullable, but thefunctionreturns'null' (see https://psalm.dev/139)Error: src/Symfony/Component/Console/Terminal.php:60:24: NullableReturnStatement: The declaredreturntype'Symfony\Component\Console\Output\AnsiColorMode'for Symfony\Component\Console\Terminal::getColorMode is not nullable, but thefunctionreturns'null' (see https://psalm.dev/139)Error: src/Symfony/Component/Console/Terminal.php:66:24: NullableReturnStatement: The declaredreturntype'Symfony\Component\Console\Output\AnsiColorMode'for Symfony\Component\Console\Terminal::getColorMode is not nullable, but thefunctionreturns'null' (see https://psalm.dev/139)Error: src/Symfony/Component/Console/Terminal.php:72:16: NullableReturnStatement: The declaredreturntype'Symfony\Component\Console\Output\AnsiColorMode'for Symfony\Component\Console\Terminal::getColorMode is not nullable, but thefunctionreturns'null' (see https://psalm.dev/139)Error: Process completed withexit code 2.

@fabpot
Copy link
Member

Thank you@julien-boudry.

@fabpotfabpot merged commit9560d73 intosymfony:6.2Sep 7, 2022
@fabpotfabpot mentioned this pull requestOct 24, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@stofstofstof approved these changes

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

5 participants

@julien-boudry@alamirault@fabpot@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp