-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add support for true colors #36802
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
77b804f
to
b5be5db
Compare
8ff5fb5
to
c8b9489
Compare
} | ||
|
||
if (!isset(static::$colors[$color])) { | ||
throw new InvalidArgumentException(sprintf('Invalid "%s" color; expected one of (%s).', $color, implode(', ', array_keys(static::$colors)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can point out here that the user should use one of the predefined colors or an hexadecimal one ?
I guess you need to reword your description, to talk about hex colors. CSS colors do support RGB and HSL (and more to come) |
src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php
Outdated
Show resolved
Hide resolved
c8b9489
to
fa9f895
Compare
Anyone willing to test on Windows? |
*/ | ||
final class Color | ||
{ | ||
private static $colors = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoudn't these be consts instead ? (Same for $availableOptions
)
Some tests with the |
fa9f895
to
6fe798b
Compare
Thanks @wouterj for testing on Windows. |
6fe798b
to
1788423
Compare
1788423
to
d066514
Compare
This PR adds support for true colors in the Console component.
Instead of adding many ways to add more colors than the current "default" ones, I've opted to only add true color support via Hex CSS colors. If you have something else (RGB, HSV, ...), you need to first convert it to a CSS color. I've also decided to not support the ANSI 256 colors as most terminals support true colors nowadays.
If true colors are not supported by the terminal, we fall back to the "nearest" default color.
<fg=green;bg=blue>
is now equivalent to<fg=#00ff00;bg=#00f>
.The
Color
class is usable outside of the Console framework as well:Rainbow time!