-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3065dbf
to
6b86489
Compare
e851fd9
to
d430f59
Compare
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.
d430f59
to
4cb8384
Compare
I agree. I just push a new version with just theses naming changes. |
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 declared return type '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 declared return type 'Symfony\Component\Console\Output\AnsiColorMode' for Symfony\Component\Console\Terminal::getColorMode is not nullable, but the function returns 'null' (see https://psalm.dev/139)
Error: src/Symfony/Component/Console/Terminal.php:49:24: NullableReturnStatement: The declared return type 'Symfony\Component\Console\Output\AnsiColorMode' for Symfony\Component\Console\Terminal::getColorMode is not nullable, but the function returns 'null' (see https://psalm.dev/139)
Error: src/Symfony/Component/Console/Terminal.php:60:24: NullableReturnStatement: The declared return type 'Symfony\Component\Console\Output\AnsiColorMode' for Symfony\Component\Console\Terminal::getColorMode is not nullable, but the function returns 'null' (see https://psalm.dev/139)
Error: src/Symfony/Component/Console/Terminal.php:66:24: NullableReturnStatement: The declared return type 'Symfony\Component\Console\Output\AnsiColorMode' for Symfony\Component\Console\Terminal::getColorMode is not nullable, but the function returns 'null' (see https://psalm.dev/139)
Error: src/Symfony/Component/Console/Terminal.php:72:16: NullableReturnStatement: The declared return type 'Symfony\Component\Console\Output\AnsiColorMode' for Symfony\Component\Console\Terminal::getColorMode is not nullable, but the function returns 'null' (see https://psalm.dev/139)
Error: Process completed with exit 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.