-
Notifications
You must be signed in to change notification settings - Fork 51
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 8 & 24 bit color #27
Comments
Interesting idea. There are a few ways to do this. I'll experiment a bit. @naturalethic What is theming? |
Generating the ANSI sequences is easy. Downsampling 24-bit color on terminals that don't support 24-bit color, e.g. Chalk does this using
I'm not going to incorporate Here is an example to show you how that could potentially look like: Example
Result |
Great stuff! Regarding theming upon some thought there's nothing you'd need to provide. People can just put together any kind of color scheme they like and provide a small library if they want. Terminals themselves can theme the standard 16 colors. |
@naturalethic Thanks! Maybe I can improve this a bit more. I'll experiment more. |
@naturalethic I played a bit more with it and whittled it down to this. const color = require("colorette")
const { rgb, ansi256, ansi16 } = require("color-convert").hex
const hex = color.generate({ rgb, ansi256, ansi16 })
const mauve = hex("#b784a7")
console.log(mauve("Mauve")) Now, compare it to what I posted above. Which one is better? const { stdout } = require("supports-color")
const hexTo = require("color-convert").hex
const { rgb, ansi256, ansi16 } = require("colorette")
const hex = color =>
stdout
? stdout.has16m
? rgb(...hexTo.rgb(color))
: ansi256(hexTo.ansi256(color))
: ansi16(hexTo.ansi16(color))
const mauve = hex("#b784a7")
console.log(mauve("Mauve")) |
Seems you could just do this: const color = require("colorette")
const hex = color.generate(require("color-convert").hex) |
Or perhaps you could document that the end user must add |
@naturalethic Opps, I did it again. #31 That adds built-in 24-bit color support. const { hex } = require("colorette")
const mauve = hex("#b784a7")
console.log(mauve("TrueColor")) \u001b[38;2;183;132;167mTrueColor\u001b[39m Terminal.app
iTerm.app (v3) |
Hey nice I was wondering if you were going to do this. |
@naturalethic Me too. Thoughts? :) |
I'll definitely be using this on my next console project. Does the performance hold up even in 24 bit? |
Yes, it does. The color factory functions ExampleImport a built-in color function and a color factory function. const { red, hex } = require("colorette") Derive a new color function. const trueRed = hex("#ff0000") From this point on you can expect the same performance out from |
I want to focus on the core functionality of this package, and simply not address 8~24 bit color at this time. |
https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
Additionally, generators for colors say,
const mauve = colorette('#b784a7')
Maybe theming too.
The text was updated successfully, but these errors were encountered: