color

package
v3.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 14

Documentation

Index

Constants

View Source
const (
	Black   = XTerm0
	Maroon  = XTerm1
	Green   = XTerm2
	Olive   = XTerm3
	Navy    = XTerm4
	Purple  = XTerm5
	Teal    = XTerm6
	Silver  = XTerm7
	Gray    = XTerm8
	Red     = XTerm9
	Lime    = XTerm10
	Yellow  = XTerm11
	Blue    = XTerm12
	Fuchsia = XTerm13
	Aqua    = XTerm14
	White   = XTerm15
)

Note that the order of these options is important -- it follows the definitions used by ECMA and XTerm. Hence any further named colors must begin at a value not less than 256.

View Source
const (
	XTerm0 = IsValid + iota
	XTerm1
	XTerm2
	XTerm3
	XTerm4
	XTerm5
	XTerm6
	XTerm7
	XTerm8
	XTerm9
	XTerm10
	XTerm11
	XTerm12
	XTerm13
	XTerm14
	XTerm15
	XTerm16
	XTerm17
	XTerm18
	XTerm19
	XTerm20
	XTerm21
	XTerm22
	XTerm23
	XTerm24
	XTerm25
	XTerm26
	XTerm27
	XTerm28
	XTerm29
	XTerm30
	XTerm31
	XTerm32
	XTerm33
	XTerm34
	XTerm35
	XTerm36
	XTerm37
	XTerm38
	XTerm39
	XTerm40
	XTerm41
	XTerm42
	XTerm43
	XTerm44
	XTerm45
	XTerm46
	XTerm47
	XTerm48
	XTerm49
	XTerm50
	XTerm51
	XTerm52
	XTerm53
	XTerm54
	XTerm55
	XTerm56
	XTerm57
	XTerm58
	XTerm59
	XTerm60
	XTerm61
	XTerm62
	XTerm63
	XTerm64
	XTerm65
	XTerm66
	XTerm67
	XTerm68
	XTerm69
	XTerm70
	XTerm71
	XTerm72
	XTerm73
	XTerm74
	XTerm75
	XTerm76
	XTerm77
	XTerm78
	XTerm79
	XTerm80
	XTerm81
	XTerm82
	XTerm83
	XTerm84
	XTerm85
	XTerm86
	XTerm87
	XTerm88
	XTerm89
	XTerm90
	XTerm91
	XTerm92
	XTerm93
	XTerm94
	XTerm95
	XTerm96
	XTerm97
	XTerm98
	XTerm99
	XTerm100
	XTerm101
	XTerm102
	XTerm103
	XTerm104
	XTerm105
	XTerm106
	XTerm107
	XTerm108
	XTerm109
	XTerm110
	XTerm111
	XTerm112
	XTerm113
	XTerm114
	XTerm115
	XTerm116
	XTerm117
	XTerm118
	XTerm119
	XTerm120
	XTerm121
	XTerm122
	XTerm123
	XTerm124
	XTerm125
	XTerm126
	XTerm127
	XTerm128
	XTerm129
	XTerm130
	XTerm131
	XTerm132
	XTerm133
	XTerm134
	XTerm135
	XTerm136
	XTerm137
	XTerm138
	XTerm139
	XTerm140
	XTerm141
	XTerm142
	XTerm143
	XTerm144
	XTerm145
	XTerm146
	XTerm147
	XTerm148
	XTerm149
	XTerm150
	XTerm151
	XTerm152
	XTerm153
	XTerm154
	XTerm155
	XTerm156
	XTerm157
	XTerm158
	XTerm159
	XTerm160
	XTerm161
	XTerm162
	XTerm163
	XTerm164
	XTerm165
	XTerm166
	XTerm167
	XTerm168
	XTerm169
	XTerm170
	XTerm171
	XTerm172
	XTerm173
	XTerm174
	XTerm175
	XTerm176
	XTerm177
	XTerm178
	XTerm179
	XTerm180
	XTerm181
	XTerm182
	XTerm183
	XTerm184
	XTerm185
	XTerm186
	XTerm187
	XTerm188
	XTerm189
	XTerm190
	XTerm191
	XTerm192
	XTerm193
	XTerm194
	XTerm195
	XTerm196
	XTerm197
	XTerm198
	XTerm199
	XTerm200
	XTerm201
	XTerm202
	XTerm203
	XTerm204
	XTerm205
	XTerm206
	XTerm207
	XTerm208
	XTerm209
	XTerm210
	XTerm211
	XTerm212
	XTerm213
	XTerm214
	XTerm215
	XTerm216
	XTerm217
	XTerm218
	XTerm219
	XTerm220
	XTerm221
	XTerm222
	XTerm223
	XTerm224
	XTerm225
	XTerm226
	XTerm227
	XTerm228
	XTerm229
	XTerm230
	XTerm231
	XTerm232
	XTerm233
	XTerm234
	XTerm235
	XTerm236
	XTerm237
	XTerm238
	XTerm239
	XTerm240
	XTerm241
	XTerm242
	XTerm243
	XTerm244
	XTerm245
	XTerm246
	XTerm247
	XTerm248
	XTerm249
	XTerm250
	XTerm251
	XTerm252
	XTerm253
	XTerm254
	XTerm255
	AliceBlue            = IsRGB | IsValid | 0xF0F8FF
	AntiqueWhite         = IsRGB | IsValid | 0xFAEBD7
	AquaMarine           = IsRGB | IsValid | 0x7FFFD4
	Azure                = IsRGB | IsValid | 0xF0FFFF
	Beige                = IsRGB | IsValid | 0xF5F5DC
	Bisque               = IsRGB | IsValid | 0xFFE4C4
	BlanchedAlmond       = IsRGB | IsValid | 0xFFEBCD
	BlueViolet           = IsRGB | IsValid | 0x8A2BE2
	Brown                = IsRGB | IsValid | 0xA52A2A
	BurlyWood            = IsRGB | IsValid | 0xDEB887
	CadetBlue            = IsRGB | IsValid | 0x5F9EA0
	Chartreuse           = IsRGB | IsValid | 0x7FFF00
	Chocolate            = IsRGB | IsValid | 0xD2691E
	Coral                = IsRGB | IsValid | 0xFF7F50
	CornflowerBlue       = IsRGB | IsValid | 0x6495ED
	Cornsilk             = IsRGB | IsValid | 0xFFF8DC
	Crimson              = IsRGB | IsValid | 0xDC143C
	DarkBlue             = IsRGB | IsValid | 0x00008B
	DarkCyan             = IsRGB | IsValid | 0x008B8B
	DarkGoldenrod        = IsRGB | IsValid | 0xB8860B
	DarkGray             = IsRGB | IsValid | 0xA9A9A9
	DarkGreen            = IsRGB | IsValid | 0x006400
	DarkKhaki            = IsRGB | IsValid | 0xBDB76B
	DarkMagenta          = IsRGB | IsValid | 0x8B008B
	DarkOliveGreen       = IsRGB | IsValid | 0x556B2F
	DarkOrange           = IsRGB | IsValid | 0xFF8C00
	DarkOrchid           = IsRGB | IsValid | 0x9932CC
	DarkRed              = IsRGB | IsValid | 0x8B0000
	DarkSalmon           = IsRGB | IsValid | 0xE9967A
	DarkSeaGreen         = IsRGB | IsValid | 0x8FBC8F
	DarkSlateBlue        = IsRGB | IsValid | 0x483D8B
	DarkSlateGray        = IsRGB | IsValid | 0x2F4F4F
	DarkTurquoise        = IsRGB | IsValid | 0x00CED1
	DarkViolet           = IsRGB | IsValid | 0x9400D3
	DeepPink             = IsRGB | IsValid | 0xFF1493
	DeepSkyBlue          = IsRGB | IsValid | 0x00BFFF
	DimGray              = IsRGB | IsValid | 0x696969
	DodgerBlue           = IsRGB | IsValid | 0x1E90FF
	FireBrick            = IsRGB | IsValid | 0xB22222
	FloralWhite          = IsRGB | IsValid | 0xFFFAF0
	ForestGreen          = IsRGB | IsValid | 0x228B22
	Gainsboro            = IsRGB | IsValid | 0xDCDCDC
	GhostWhite           = IsRGB | IsValid | 0xF8F8FF
	Gold                 = IsRGB | IsValid | 0xFFD700
	Goldenrod            = IsRGB | IsValid | 0xDAA520
	GreenYellow          = IsRGB | IsValid | 0xADFF2F
	Honeydew             = IsRGB | IsValid | 0xF0FFF0
	HotPink              = IsRGB | IsValid | 0xFF69B4
	IndianRed            = IsRGB | IsValid | 0xCD5C5C
	Indigo               = IsRGB | IsValid | 0x4B0082
	Ivory                = IsRGB | IsValid | 0xFFFFF0
	Khaki                = IsRGB | IsValid | 0xF0E68C
	Lavender             = IsRGB | IsValid | 0xE6E6FA
	LavenderBlush        = IsRGB | IsValid | 0xFFF0F5
	LawnGreen            = IsRGB | IsValid | 0x7CFC00
	LemonChiffon         = IsRGB | IsValid | 0xFFFACD
	LightBlue            = IsRGB | IsValid | 0xADD8E6
	LightCoral           = IsRGB | IsValid | 0xF08080
	LightCyan            = IsRGB | IsValid | 0xE0FFFF
	LightGoldenrodYellow = IsRGB | IsValid | 0xFAFAD2
	LightGray            = IsRGB | IsValid | 0xD3D3D3
	LightGreen           = IsRGB | IsValid | 0x90EE90
	LightPink            = IsRGB | IsValid | 0xFFB6C1
	LightSalmon          = IsRGB | IsValid | 0xFFA07A
	LightSeaGreen        = IsRGB | IsValid | 0x20B2AA
	LightSkyBlue         = IsRGB | IsValid | 0x87CEFA
	LightSlateGray       = IsRGB | IsValid | 0x778899
	LightSteelBlue       = IsRGB | IsValid | 0xB0C4DE
	LightYellow          = IsRGB | IsValid | 0xFFFFE0
	LimeGreen            = IsRGB | IsValid | 0x32CD32
	Linen                = IsRGB | IsValid | 0xFAF0E6
	MediumAquamarine     = IsRGB | IsValid | 0x66CDAA
	MediumBlue           = IsRGB | IsValid | 0x0000CD
	MediumOrchid         = IsRGB | IsValid | 0xBA55D3
	MediumPurple         = IsRGB | IsValid | 0x9370DB
	MediumSeaGreen       = IsRGB | IsValid | 0x3CB371
	MediumSlateBlue      = IsRGB | IsValid | 0x7B68EE
	MediumSpringGreen    = IsRGB | IsValid | 0x00FA9A
	MediumTurquoise      = IsRGB | IsValid | 0x48D1CC
	MediumVioletRed      = IsRGB | IsValid | 0xC71585
	MidnightBlue         = IsRGB | IsValid | 0x191970
	MintCream            = IsRGB | IsValid | 0xF5FFFA
	MistyRose            = IsRGB | IsValid | 0xFFE4E1
	Moccasin             = IsRGB | IsValid | 0xFFE4B5
	NavajoWhite          = IsRGB | IsValid | 0xFFDEAD
	OldLace              = IsRGB | IsValid | 0xFDF5E6
	OliveDrab            = IsRGB | IsValid | 0x6B8E23
	Orange               = IsRGB | IsValid | 0xFFA500
	OrangeRed            = IsRGB | IsValid | 0xFF4500
	Orchid               = IsRGB | IsValid | 0xDA70D6
	PaleGoldenrod        = IsRGB | IsValid | 0xEEE8AA
	PaleGreen            = IsRGB | IsValid | 0x98FB98
	PaleTurquoise        = IsRGB | IsValid | 0xAFEEEE
	PaleVioletRed        = IsRGB | IsValid | 0xDB7093
	PapayaWhip           = IsRGB | IsValid | 0xFFEFD5
	PeachPuff            = IsRGB | IsValid | 0xFFDAB9
	Peru                 = IsRGB | IsValid | 0xCD853F
	Pink                 = IsRGB | IsValid | 0xFFC0CB
	Plum                 = IsRGB | IsValid | 0xDDA0DD
	PowderBlue           = IsRGB | IsValid | 0xB0E0E6
	RebeccaPurple        = IsRGB | IsValid | 0x663399
	RosyBrown            = IsRGB | IsValid | 0xBC8F8F
	RoyalBlue            = IsRGB | IsValid | 0x4169E1
	SaddleBrown          = IsRGB | IsValid | 0x8B4513
	Salmon               = IsRGB | IsValid | 0xFA8072
	SandyBrown           = IsRGB | IsValid | 0xF4A460
	SeaGreen             = IsRGB | IsValid | 0x2E8B57
	Seashell             = IsRGB | IsValid | 0xFFF5EE
	Sienna               = IsRGB | IsValid | 0xA0522D
	Skyblue              = IsRGB | IsValid | 0x87CEEB
	SlateBlue            = IsRGB | IsValid | 0x6A5ACD
	SlateGray            = IsRGB | IsValid | 0x708090
	Snow                 = IsRGB | IsValid | 0xFFFAFA
	SpringGreen          = IsRGB | IsValid | 0x00FF7F
	SteelBlue            = IsRGB | IsValid | 0x4682B4
	Tan                  = IsRGB | IsValid | 0xD2B48C
	Thistle              = IsRGB | IsValid | 0xD8BFD8
	Tomato               = IsRGB | IsValid | 0xFF6347
	Turquoise            = IsRGB | IsValid | 0x40E0D0
	Violet               = IsRGB | IsValid | 0xEE82EE
	Wheat                = IsRGB | IsValid | 0xF5DEB3
	WhiteSmoke           = IsRGB | IsValid | 0xF5F5F5
	YellowGreen          = IsRGB | IsValid | 0x9ACD32
)
View Source
const (
	Grey           = Gray
	DimGrey        = DimGray
	DarkGrey       = DarkGray
	DarkSlateGrey  = DarkSlateGray
	LightGrey      = LightGray
	LightSlateGrey = LightSlateGray
	SlateGrey      = SlateGray
)

These are aliases for the color gray, because some of us spell it as grey.

View Source
const (
	// Reset is used to indicate that the color should use the
	// vanilla terminal colors.  (Basically go back to the defaults.)
	Reset = IsSpecial | iota

	// None indicates that we should not change the color from
	// whatever is already displayed.  This can only be used in limited
	// circumstances.
	None
)

Special colors.

Variables

View Source
var ColorValues = map[Color]int32{}/* 379 elements not displayed */

ColorValues maps color constants to their RGB values.

View Source
var Names = map[string]Color{}/* 146 elements not displayed */

Names holds the written names of colors. Useful to present a list of recognized named colors.

Functions

This section is empty.

Types

type Color

type Color uint32

Color represents a color. The low numeric values are the same as used by ECMA-48, and beyond that XTerm.

For Color names we use the W3C approved color names.

Note that on various terminals colors may be approximated however, or not supported at all. If no suitable representation for a color is known, the library will simply not set any color, deferring to whatever default attributes the terminal uses.

const (
	// Default is used to leave the Color unchanged from whatever
	// system or terminal default may exist.  It's also the zero value.
	Default Color = 0

	// IsValid is used to indicate the color value is actually
	// valid (initialized).  This is useful to permit the zero value
	// to be treated as the default. This should not be used
	// directly by applications.  Use the IsValid method on Color instead.
	IsValid Color = 1 << 31

	// IsRGB is used to indicate that the numeric value is not
	// a known color constant, but rather an RGB value.  The lower
	// order 3 bytes are RGB.  This should not be used directly,
	// instead use the Color.IsRGB method.
	IsRGB Color = 1 << 30

	// IsSpecial is a flag used to indicate that the values have
	// special meaning, and live outside of the color space(s).
	// This should not be used directly by applications.
	IsSpecial Color = 1 << 29
)

func Find

func Find(c Color, palette []Color) Color

Find attempts to find a given color, or the best match possible for it, from the palette given. This is an expensive operation, so results should be cached by the caller.

func FromImageColor

func FromImageColor(imageColor ic.Color) Color

FromImageColor converts an image/color.Color into Color. The alpha value is limited to just zero and non-zero, so it should be tracked separately if full detail is needed. (A zero alpha becomes the default color, which means no color change at all.)

func GetColor

func GetColor(name string) 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 NewHexColor

func NewHexColor(v int32) Color

NewHexColor returns a color using the given 24-bit RGB value.

func NewRGBColor

func NewRGBColor(r, g, b int32) Color

NewRGBColor returns a new color with the given red, green, and blue values. Each value must be represented in the range 0-255.

func PaletteColor

func PaletteColor(index int) Color

PaletteColor creates a color based on the palette index.

func (Color) CSS

func (c Color) CSS() string

CSS returns the CSS hex string ( #ABCDEF ) if valid if not a valid color returns empty string

func (Color) Hex

func (c Color) Hex() int32

Hex returns the color's hexadecimal RGB 24-bit value with each component consisting of a single byte, R << 16 | G << 8 | B. If the color is unknown or unset, -1 is returned.

func (Color) IsRGB

func (c Color) IsRGB() bool

IsRGB is true if the color is an RGB specific value.

func (Color) Name

func (c Color) Name(css ...bool) string

Name returns W3C name or an empty string if no arguments if passed true as an argument it will falls back to the CSS hex string if no W3C name found '#ABCDEF'

func (Color) RGB

func (c Color) RGB() (int32, int32, int32)

RGB returns the red, green, and blue components of the color, with each component represented as a value 0-255. In the event that the color cannot be broken up (not set usually), -1 is returned for each value.

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

RGBA makes these colors directly usable as imageColor colors. The values are scaled only to 16 bits. Invalid colors are returned with all values being zero (notably the alpha is zero, so fully transparent), otherwise the alpha channel is set to 0xffff (fully opaque).

func (Color) String

func (c Color) String() string

String implements fmt.Stringer to return either the W3C name if it has one or the CSS hex string '#ABCDEF'

func (Color) TrueColor

func (c Color) TrueColor() Color

TrueColor returns the true color (RGB) version of the provided color. This is useful for ensuring color accuracy when using named colors. This will override terminal theme colors.

func (Color) Valid

func (c Color) Valid() bool

Valid indicates the color is a valid value (has been set).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL