Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
e851fd9 tod430f59Comparejulien-boudry commentedAug 27, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Do you prefer as actually: Terminal::getTermColorMode();Terminal::setTermColorMode();(private) Terminal::$termColorMode; Or? Terminal::getColorMode();Terminal::setColorMode();(private) Terminal::$colorMode; |
I prefer |
…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.
I agree. I just push a new version with just theses naming changes. |
julien-boudry commentedSep 7, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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:
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. |
Thank you@julien-boudry. |
Continue#46944
Terminal Color Mode refactoring: Adding a way to force color mode by the dev. user (with a new method), fewer
getenv()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.