Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "log" "github.com/kenshaw/colors" ) func main() { for _, s := range []string{ "red", "rgba(192, 192, 192, 255)", "navajo white", "#ffeeaa", "rgb(106,90,205)", "rgb(0,255,0)", "hex(f,e,a)", "#fff", "rgba(26,33,80,22)", "#cdcdcd80", "#cdcdcdff", "hex(0,0,0,0)", } { c, err := colors.Parse(s) if err != nil { log.Fatal(err) } fmt.Println(c) } }
Output: red silver navajowhite #fea slateblue lime #0f0e0a white #1a215016 #cdcdcd80 #cdcdcd transparent
Index ¶
- func Is(a, b color.Color) bool
- func Map() map[NamedColor]Color
- func MapString() map[string]Color
- func Register(n NamedColor, clr color.Color)
- func RegisterName(s string, clr color.Color)
- type Color
- func FromColor(clr color.Color) Color
- func FromHex(s string) (Color, bool)
- func FromName(s string) (Color, bool)
- func FromRGB(s string) (Color, bool)
- func FromRGBA(s string) (Color, bool)
- func FromWeb(s string) (c Color, ok bool)
- func New(r, g, b, a uint8) Color
- func Parse(s string) (Color, error)
- func ToColor(r, g, b, a uint8, name string) Color
- func (c Color) AsHex() string
- func (c Color) AsRGB() string
- func (c Color) AsRGBA() string
- func (c Color) AsText() string
- func (c Color) AsWeb() string
- func (c Color) AsWebShort() string
- func (c Color) Dark() bool
- func (c Color) Format(f fmt.State, verb rune)
- func (c Color) Is(clr color.Color) bool
- func (c Color) Light() bool
- func (c *Color) MarshalText() ([]byte, error)
- func (c Color) Name() string
- func (c *Color) Pflag() Pflag
- func (c Color) RGBA() (r, g, b, a uint32)
- func (c *Color) UnmarshalText(text []byte) error
- type Error
- type NamedColor
- type Pflag
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(n NamedColor, clr color.Color)
Register registers an additional color.
func RegisterName ¶
RegisterName registers an additional color.
Types ¶
type Color ¶
type Color struct {
R, G, B, A uint8
NamedColor NamedColor
}
Color is a color.
func FromColor ¶
FromColor converts a standard color.Color to a color.
func FromWeb ¶
FromWeb converts a web string to a color.
Cribbed from https://stackoverflow.com/questions/54197913/parse-hex-string-to-image-color
func (Color) AsRGBA ¶
AsRGBA returns the color formatted as a rgba string, ex: rgba(255,255,255,255).
func (Color) AsWebShort ¶
AsWebShort returns the shortest possible formatted web string, ex: #fff.
func (Color) Format ¶
Format satisfies the fmt.Formatter interface.
func (*Color) MarshalText ¶
MarshalText satisfies the encoding.TextMarshaler interface.
func (*Color) Pflag ¶
Pflag returns a Pflag wrapping the color, that can be used with various command-line packages, such as cobra, and satisfies the pflag.Value interface.
func (Color) RGBA ¶
RGBA satisfies the color.Color interface.
func (*Color) UnmarshalText ¶
UnmarshalText satisfies the encoding.TextUnmarshaler interface.
type Error ¶
type Error string
Error is a error.
const ( // ErrInvalidColor is invalid color error. ErrInvalidColor Error = "invalid color" )
Errors.
type NamedColor ¶
type NamedColor string
NamedColor is a named color.
const ( Aliceblue NamedColor = "aliceblue" Antiquewhite NamedColor = "antiquewhite" Aqua NamedColor = "aqua" Aquamarine NamedColor = "aquamarine" Azure NamedColor = "azure" Beige NamedColor = "beige" Bisque NamedColor = "bisque" Black NamedColor = "black" Blanchedalmond NamedColor = "blanchedalmond" Blue NamedColor = "blue" Blueviolet NamedColor = "blueviolet" Brown NamedColor = "brown" Burlywood NamedColor = "burlywood" Cadetblue NamedColor = "cadetblue" Chartreuse NamedColor = "chartreuse" Chocolate NamedColor = "chocolate" Coral NamedColor = "coral" Cornflowerblue NamedColor = "cornflowerblue" Cornsilk NamedColor = "cornsilk" Crimson NamedColor = "crimson" Cyan NamedColor = "cyan" Darkblue NamedColor = "darkblue" Darkcyan NamedColor = "darkcyan" Darkgoldenrod NamedColor = "darkgoldenrod" Darkgray NamedColor = "darkgray" Darkgreen NamedColor = "darkgreen" Darkgrey NamedColor = "darkgrey" Darkkhaki NamedColor = "darkkhaki" Darkmagenta NamedColor = "darkmagenta" Darkolivegreen NamedColor = "darkolivegreen" Darkorange NamedColor = "darkorange" Darkorchid NamedColor = "darkorchid" Darkred NamedColor = "darkred" Darksalmon NamedColor = "darksalmon" Darkseagreen NamedColor = "darkseagreen" Darkslateblue NamedColor = "darkslateblue" Darkslategray NamedColor = "darkslategray" Darkslategrey NamedColor = "darkslategrey" Darkturquoise NamedColor = "darkturquoise" Darkviolet NamedColor = "darkviolet" Deeppink NamedColor = "deeppink" Deepskyblue NamedColor = "deepskyblue" Dimgray NamedColor = "dimgray" Dimgrey NamedColor = "dimgrey" Dodgerblue NamedColor = "dodgerblue" Firebrick NamedColor = "firebrick" Floralwhite NamedColor = "floralwhite" Forestgreen NamedColor = "forestgreen" Fuchsia NamedColor = "fuchsia" Gainsboro NamedColor = "gainsboro" Ghostwhite NamedColor = "ghostwhite" Gold NamedColor = "gold" Goldenrod NamedColor = "goldenrod" Gray NamedColor = "gray" Green NamedColor = "green" Greenyellow NamedColor = "greenyellow" Grey NamedColor = "grey" Honeydew NamedColor = "honeydew" Hotpink NamedColor = "hotpink" Indianred NamedColor = "indianred" Indigo NamedColor = "indigo" Ivory NamedColor = "ivory" Khaki NamedColor = "khaki" Lavender NamedColor = "lavender" Lavenderblush NamedColor = "lavenderblush" Lawngreen NamedColor = "lawngreen" Lemonchiffon NamedColor = "lemonchiffon" Lightblue NamedColor = "lightblue" Lightcoral NamedColor = "lightcoral" Lightcyan NamedColor = "lightcyan" Lightgoldenrodyellow NamedColor = "lightgoldenrodyellow" Lightgray NamedColor = "lightgray" Lightgreen NamedColor = "lightgreen" Lightgrey NamedColor = "lightgrey" Lightpink NamedColor = "lightpink" Lightsalmon NamedColor = "lightsalmon" Lightseagreen NamedColor = "lightseagreen" Lightskyblue NamedColor = "lightskyblue" Lightslategray NamedColor = "lightslategray" Lightslategrey NamedColor = "lightslategrey" Lightsteelblue NamedColor = "lightsteelblue" Lightyellow NamedColor = "lightyellow" Lime NamedColor = "lime" Limegreen NamedColor = "limegreen" Linen NamedColor = "linen" Magenta NamedColor = "magenta" Maroon NamedColor = "maroon" Mediumaquamarine NamedColor = "mediumaquamarine" Mediumblue NamedColor = "mediumblue" Mediumorchid NamedColor = "mediumorchid" Mediumpurple NamedColor = "mediumpurple" Mediumseagreen NamedColor = "mediumseagreen" Mediumslateblue NamedColor = "mediumslateblue" Mediumspringgreen NamedColor = "mediumspringgreen" Mediumturquoise NamedColor = "mediumturquoise" Mediumvioletred NamedColor = "mediumvioletred" Midnightblue NamedColor = "midnightblue" Mintcream NamedColor = "mintcream" Mistyrose NamedColor = "mistyrose" Moccasin NamedColor = "moccasin" Oldlace NamedColor = "oldlace" Olive NamedColor = "olive" Olivedrab NamedColor = "olivedrab" Orange NamedColor = "orange" Orangered NamedColor = "orangered" Orchid NamedColor = "orchid" Palegoldenrod NamedColor = "palegoldenrod" Palegreen NamedColor = "palegreen" Paleturquoise NamedColor = "paleturquoise" Palevioletred NamedColor = "palevioletred" Papayawhip NamedColor = "papayawhip" Peachpuff NamedColor = "peachpuff" Peru NamedColor = "peru" Pink NamedColor = "pink" Plum NamedColor = "plum" Powderblue NamedColor = "powderblue" Purple NamedColor = "purple" Red NamedColor = "red" Rosybrown NamedColor = "rosybrown" Royalblue NamedColor = "royalblue" Saddlebrown NamedColor = "saddlebrown" Salmon NamedColor = "salmon" Sandybrown NamedColor = "sandybrown" Seagreen NamedColor = "seagreen" Seashell NamedColor = "seashell" Sienna NamedColor = "sienna" Silver NamedColor = "silver" Skyblue NamedColor = "skyblue" Slateblue NamedColor = "slateblue" Slategray NamedColor = "slategray" Slategrey NamedColor = "slategrey" Snow NamedColor = "snow" Springgreen NamedColor = "springgreen" Steelblue NamedColor = "steelblue" Tan NamedColor = "tan" Teal NamedColor = "teal" Thistle NamedColor = "thistle" Tomato NamedColor = "tomato" Transparent NamedColor = "transparent" Turquoise NamedColor = "turquoise" Violet NamedColor = "violet" Wheat NamedColor = "wheat" White NamedColor = "white" Whitesmoke NamedColor = "whitesmoke" Yellow NamedColor = "yellow" Yellowgreen NamedColor = "yellowgreen" )
Named colors.
func (NamedColor) Format ¶
func (c NamedColor) Format(f fmt.State, verb rune)
Format satisfies the fmt.Formatter interface.
func (NamedColor) RGBA ¶
func (c NamedColor) RGBA() (r, g, b, a uint32)
RGBA satisfies the color.Color interface.
type Pflag ¶
type Pflag struct {
// contains filtered or unexported fields
}
Pflag wraps a color, for use with command-line packages, such as cobra. Satisfies the pflag.Value interface.