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

Arbitrary RGB color support #131

Open
quackduck opened this issue Jan 18, 2021 · 10 comments
Open

Arbitrary RGB color support #131

quackduck opened this issue Jan 18, 2021 · 10 comments

Comments

@quackduck
Copy link

Can we add truecolor support? The ability to specify any R, G and B value?

@quackduck
Copy link
Author

Let me know what you think, @fatih!

@regnaio
Copy link

regnaio commented Aug 29, 2021

Can we please have orange? @fatih

@quackduck
Copy link
Author

This library can make it easy to implement: https://github.com/jwalton/gchalk (it also auto-detects terminal support levels)

I can make a PR that uses this library, but I'm not sure whether @fatih would be okay with using another color library.

@quackduck quackduck changed the title Truecolor support Arbitrary RGB color support Aug 30, 2021
@fatih
Copy link
Owner

fatih commented Mar 12, 2023

I like the idea. @quackduck can you write how you want to tackle this? Do you plan to introduce a new API? or just change the underlying implementation? Before we go down this road, I want to first understand what the implications are, and whether it's worth adding it, and if we add, how I want to add it (I don't want to break existing code, because use the color package now for years based on the assumption that it uses ANSI escape codes).

@quackduck
Copy link
Author

I think a new API would probably be the best way to do this since changing the underlying implementation could break stuff. Not sure if I can make a PR in the near future, though.

@Kevin-Rudy
Copy link

24-bit true color with ANSI escape sequences can be used for encoding arbitrary colors. Refer:https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797.
For example, if you want to obtain an orange color, you can use the code color.New(38, 2, 255, 128, 0), where the first two parameters are according to ANSI standards, and the last three parameters are the corresponding RGB values of the color.

@fatih
Copy link
Owner

fatih commented Jan 23, 2024

@Kevin-Rudy thanks for the tip. It never occurred to me to use the RGB colors that way, but this is nice. We could easily document this in our README, and I'll think if we can simplify it to some new functions, i.e: color.NewRGBFg(255, 128, 0) for foreground, and color.NewRGBBg for background. I don't like the name though, but I'll think about it. Meanwhile if anyone has better ideas, please let me know.

@fatih
Copy link
Owner

fatih commented Jan 23, 2024

Oh here is how it looks using the code:

package main

import (
	"github.com/fatih/color"
)

func main() {
	a := color.New(38, 2, 255, 128, 0)
	a.Println("This is orange")
	a.Println("what's up")

	b := color.New(48, 2, 255, 128, 0)
	b.Println("This is orange")
	b.Println("what's up")
}

ScreenShot-2024-01-23-12 08 47@2x

@bschaatsbergen
Copy link

bschaatsbergen commented Mar 23, 2024

I'll think if we can simplify it to some new functions, i.e: color.NewRGBFg(255, 128, 0) for foreground, and color.NewRGBBg for background.

Hey Fatih, is there any way I can help with implementing this new API? I think it can be very useful considering how widely used this package is 👍🏼

@fatih
Copy link
Owner

fatih commented Mar 24, 2024

Hi @bschaatsbergen I created a PR, could you try it out and share any feedback you have? Thank you: #225

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

No branches or pull requests

5 participants