Skip to content
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

Support for CSS named colors #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

meowgorithm
Copy link
Collaborator

This adds support for CSS named colors via Gamut, so you can do something like the following (per #29):

p := termenv.ColorProfile()
s := termenv.String("Hello!").Foreground(p.Color("red")).String()

@meowgorithm
Copy link
Collaborator Author

meowgorithm commented Dec 4, 2020

Oh! It's also worth nothing that this was implemented against the new CSS palette in github.com/muesli/gamut@master. It would probably make more sense, of course, to update this PR against a proper gamut release.

@meowgorithm meowgorithm changed the title Support CSS named colors Support for CSS named colors Dec 4, 2020
color.go Outdated
@@ -91,6 +96,8 @@ func (p Profile) Color(s string) Color {
var c Color
if strings.HasPrefix(s, "#") {
c = RGBColor(s)
} else if _, ok := palette.CSS.Color(s); ok {
Copy link
Owner

Choose a reason for hiding this comment

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

I think this should be the last resort and we should try and convert the string to an integer first and, if that succeeds, treat it as a regular ANSI color. Not that there's currently a clash, but if someone added "8" as a color name to that palette, it would override the ANSI color. We wouldn't want that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Updated.

@muesli
Copy link
Owner

muesli commented Dec 7, 2020

Just out: gamut v0.2.0 😄

@meowgorithm
Copy link
Collaborator Author

Alright, bumped to Gamut v0.2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants