Comments (25)
Just a quick note (I'm traveling atm) that I did something similair a while back. You can probably find the discussion under chalk's issues and see my implementation here: https://github.com/jbnicolai/ansi-256-colors
from ansi-styles.
@jbnicolai I stole the RGB -> ANSI 256 formula from there 😉 This proposal does something a little more than just that, though. If you wanted to, we could beef up the ansi-256-colors repository to do the color-to-ANSI-code conversions and then let this library use that? Though ansi-256-colors is a bit of a misnomer since we'd also be supporting truecolor as well.
from ansi-styles.
Nah, I'm perfectly happy retiring that repository and beefing up the chalk/ansi-styles/supports-color stack, although I'm starting to think we should maybe move this set of repositories to their own organisation.
How would you feel about that, @sindresorhus?
from ansi-styles.
http://github.com/chalk seems inactive. Github is pretty good about releasing inactive accounts. http://github.com/chalkjs is also unclaimed.
EDIT: @jbnicolai don't forget ansi-regex and strip-ansi.
from ansi-styles.
@Qix- yeah, completely agree those should probably come with as well. It's @sindresorhus' call though :)
from ansi-styles.
👍
from ansi-styles.
I'm looking at the existing code for this repo. It's pretty basic. It'd be pretty much a complete re-write.
from ansi-styles.
I've started a bit of a re-write as it is. Any thoughts on this @sindresorhus?
from ansi-styles.
I used up all my time today moving everything over to the chalk
org. Will get back to this in a couple of days when I have more time. Tweeted about getting feedback on this, so we can hopefully get some more eyes on it.
from ansi-styles.
Sounds good 👍
from ansi-styles.
My package https://github.com/sunesimonsen/magicpen supports 256 with backwards compatibility with 16 color terminals. Maybe that could be a source of inspiration, the ansi serializer is here: https://github.com/sunesimonsen/magicpen/blob/master/lib/AnsiSerializer.js
from ansi-styles.
@sunesimonsen and what of 16m colors? @jbnicolai already had a module that did something very similar. This proposal does something completely different.
from ansi-styles.
@Qix- we don't support that yet, but I'm curious to see what you come up with.
from ansi-styles.
@sunesimonsen as in the original post here, we'd be using/working with full RGB values and degrading into their lower forms (truecolor -> 256 -> 16 colors).
from ansi-styles.
x-post: chalk/chalk#73
from ansi-styles.
Also, another question is: where should everything go?
We have a few moving parts here:
- Level detection
- Color manipulation functionality (hue shifting, lightness adjustments, RGB <-> HSV/HSL conversions, etc.)
- Degradation from truecolor to 256/basic values
- The fact we want to be able to map these to basic colors (i.e.
rgb(255, 0, 0)
should map to31
instead of38;2;255;0;0
) - Listing above combinations (and applying labels to them)
- Styles (bold, italic, underline, inverse, etc.)
- The API for stringing them together
Some of the above are obvious (i.e. stringing them together would occur in chalk proper), but the others?
As well, this has the potential to introduce a major performance hit if not done correctly (color modifications aren't nearly as quick as lookups). Memoization will be important here.
I propose the following:
- Level Detection: supports-color
- Color Manipulation: ansi-styles / new module (see note below)
- Degradation: ansi-styles / new module (see note below)
- Color Mapping: ansi-styles
- Map Labels: ansi-styles
- Styles: ansi-styles
- API: chalk
Color manipulation (lightness, hue, etc.) was originally going to happen with color-js. However, upon actually looking at the code, it doesn't look very performant / memory conscious. The code is under the BSD clause 2, which means we can use the algorithms with attribution and build our own structure around it.
But that's all up to @sindresorhus.
from ansi-styles.
Oh I'm not done.
Another consideration: if we go from high->low resolution on colors, the 16 color palette is going to be tricky.
There are a few ways we can interpret RGB values for the 16 color palette.
By the math, regular colors should be 0..127
and bright colors should be 128..255
, though that's not necessarily true on all VGA systems. Do we enforce this idea? People usually have them re-mapped anyway.
Surprisingly, Windows XP gets it the closest.
from ansi-styles.
@Qix- I also use full RGB values and degrading them to the 256 and 16 color palette. I wanted 256 colors to work in terminals that supports 256 colors but can't be detected as such, so we wrap the 256 color escape sequence in a 16 color escape sequence. Old terminals will ignore the 256 color escape sequence and fallback to the 16 color escape sequence. It is a bit hacky, but it works.
from ansi-styles.
@sunesimonsen Ehh I feel like that's a workaround that will backfire on some terminals. Plus that craps up the terminal with more data than it needs - TTY operations are expensive as it is. Cool hack, though. Never really thought about that.
from ansi-styles.
@Qix- I'm not saying you should copy that, I'm just telling you what I have done.
from ansi-styles.
@sunesimonsen that's pretty awesome actually 😄 - although I don't suggest we copy that here
from ansi-styles.
The fact is the color operations will be easy, it's the API that's troublesome.
from ansi-styles.
I've made a PR for color-convert
for ansi16/256 color degradation algorithms.
from ansi-styles.
PR as been merged and released as [email protected].
from ansi-styles.
Thank you @MoOx :)
from ansi-styles.
Related Issues (20)
- blackBright is mentioned in README but is not implemented HOT 17
- NPM install error HOT 7
- Ambiguous error when keyword doesn't exist HOT 10
- Did the 2.2.0 release disappear? HOT 3
- Unable to install the package HOT 1
- missing module => 'color-convert' HOT 1
- Why the open/close API HOT 6
- No greenBright open and close HOT 1
- blackBright doesn't exist
- Uncaught SyntaxError: Use of const in strict mode. HOT 2
- Syntax error in IE11 due to arrow function currying HOT 4
- IE11 syntax error HOT 3
- Why is @types/color-name a production dependency? HOT 4
- Provide es5 lib output HOT 2
- Add support for overline HOT 6
- Can't import into TypeScript node project HOT 2
- Add support for superscript and subscript HOT 2
- Problem from version`5+` to Regex when using ReactNative Hermes engine HOT 1
- '[email protected]' is not in the npm registry. HOT 1
- Blinking text HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansi-styles.