colorstring icon indicating copy to clipboard operation
colorstring copied to clipboard

Add support for 256color xterm codes

Open jordansissel opened this issue 11 years ago • 10 comments

  • 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

jordansissel avatar Jul 13 '14 05:07 jordansissel

Visual test code: https://gist.github.com/jordansissel/49f3a76681987b08de4e

jordansissel avatar Jul 13 '14 05:07 jordansissel

screen shot 2014-07-12 at 10 32 56 pm

jordansissel avatar Jul 13 '14 05:07 jordansissel

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?

jordansissel avatar Jul 13 '14 05:07 jordansissel

  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"))

screen shot 2014-07-12 at 10 48 45 pm

jordansissel avatar Jul 13 '14 05:07 jordansissel

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?

mitchellh avatar Jul 13 '14 15:07 mitchellh

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.

jordansissel avatar Jul 14 '14 04:07 jordansissel

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. screen shot 2014-07-13 at 9 45 37 pm

jordansissel avatar Jul 14 '14 04:07 jordansissel

This is reasonable. Let me take one quick review again tomorrow or tonight then I'll merge it in. Thanks!

mitchellh avatar Jul 15 '14 03:07 mitchellh

256 color support would be great. Any update on this?

mpolden avatar Jul 24 '14 19:07 mpolden

@mitchellh bump? ^ :)

jippi avatar Oct 05 '17 13:10 jippi