colorstring
colorstring copied to clipboard
Add support for 256color xterm codes
- 216-color RGB cube is supported as 'rgb' with range 0-5 for each color
- 16-color Grayscale is supported as 'grayN' where N is 0-15
Visual test code: https://gist.github.com/jordansissel/49f3a76681987b08de4e

Ready for review!
Specific feedback requested:
- Is the
[rgb]syntax OK? - How about the
[grayN]syntax? - Should we also add
[greyN]for alternate spelling? - Need more tests?
fmt.Printf("%s\n", colorstring.Color("[_200_]this should be red"))
fmt.Printf("%s\n", colorstring.Color("[_020_]this should be green"))
fmt.Printf("%s\n", colorstring.Color("[_002_]this should be blue"))
fmt.Printf("%s\n", colorstring.Color("[_220_]this should be yellow"))
fmt.Printf("%s\n", colorstring.Color("[_022_]this should be cyan"))
fmt.Printf("%s\n", colorstring.Color("[_202_]this should be purple"))
fmt.Printf("%s\n", colorstring.Color("[_222_]this should be grey"))

Hey! Looks good. Questoin: why not just use the 256-color color number as shown here? http://misc.flogisoft.com/bash/tip_colors_and_formatting
Is the 0-6 "intensity" of a color some standard thing I'm unaware of? It might be easier to use the color numbers because then people can look it up. No?
The reason for the rgb syntax is that the numbers don't really have semantic meaning. Like colors in the web, where we do #RRGGBB for 3 one-byte tuples (24 bit color), instead of say, using a 24bit value as a number (#8888FF is way more readable than 16734296, there's no sane relationship between the numbers). The #8888FF is "88" on a scale of 00 to FF for intensity of red and green, etc.
So terminal colors, is 216 colors of a 6x6x6 cube, so I picked base 6 (0-5) encoded as 3 digits RGB. Much easier for me to predict what a color will be [115] is 1 red, 1 green, 5 blue. Thinking in RGB is more natural to me, rather than having to compute this value before telling the computer what the terminal code for the color I want is.
By way of example of the 'intensity' scale of rgb, here's what Apple Keynote offers for color selection for sliders of red, green, and blue. 0-255 here, but same principle applies to the 0-5 scale 216 colors gives us.

This is reasonable. Let me take one quick review again tomorrow or tonight then I'll merge it in. Thanks!
256 color support would be great. Any update on this?
@mitchellh bump? ^ :)