Skip to content

Commit

Permalink
Document and publish color names and RGB values. (#151)
Browse files Browse the repository at this point in the history
* Document and publish color names and RGB values.

* Fix failing tests.
  • Loading branch information
kimtore authored and gdamore committed Jun 21, 2017
1 parent 1f66b72 commit 01ac1e4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ const (
ColorSlateGrey = ColorSlateGray
)

var colorValues = map[Color]int32{
// ColorValues maps color constants to their RGB values.
var ColorValues = map[Color]int32{
ColorBlack: 0x000000,
ColorMaroon: 0x800000,
ColorGreen: 0x008000,
Expand Down Expand Up @@ -817,7 +818,9 @@ var colorValues = map[Color]int32{
ColorYellowGreen: 0x9ACD32,
}

var colorNames = map[string]Color{
// ColorNames holds the written names of colors. Useful to present a list of
// recognized named colors.
var ColorNames = map[string]Color{
"black": ColorBlack,
"maroon": ColorMaroon,
"green": ColorGreen,
Expand Down Expand Up @@ -973,7 +976,7 @@ func (c Color) Hex() int32 {
if c&ColorIsRGB != 0 {
return (int32(c) & 0xffffff)
}
if v, ok := colorValues[c]; ok {
if v, ok := ColorValues[c]; ok {
return v
}
return -1
Expand Down Expand Up @@ -1004,7 +1007,7 @@ func NewHexColor(v int32) Color {
// GetColor creates a Color from a color name (W3C name). A hex value may
// be supplied as a string in the format "#ffffff".
func GetColor(name string) Color {
if c, ok := colorNames[name]; ok {
if c, ok := ColorNames[name]; ok {
return c
}
if len(name) == 7 && name[0] == '#' {
Expand Down

0 comments on commit 01ac1e4

Please sign in to comment.