Documentation ¶
Overview ¶
Package color provides functions for creating colored strings.
There are several functions provided to make it easy to set foreground colors.
// creates a string with a red foreground color color.Red("uh oh")
Colors can be globally enabled or disabled by using SetEnabled. If you wish to control colors in a local scope and not affect the global state, create a Colorer instance.
var c color.Colorer // Disable colors only for this Colorer c.SetEnabled(false) s := c.Red("uh oh") // Will not be colored
This package also supports the NO_COLOR environment variable. If NO_COLOR is set with any value, colors will be disabled. See https://no-color.org for more details.
Index ¶
- func Black(s string) string
- func Blue(s string) string
- func Cyan(s string) string
- func Green(s string) string
- func IsNoColorEnvSet() bool
- func Magenta(s string) string
- func Red(s string) string
- func SetEnabled(e bool)
- func White(s string) string
- func Yellow(s string) string
- type Colorer
- func (c *Colorer) Black(s string) string
- func (c *Colorer) Blue(s string) string
- func (c *Colorer) Cyan(s string) string
- func (c *Colorer) Green(s string) string
- func (c *Colorer) Magenta(s string) string
- func (c *Colorer) Red(s string) string
- func (c *Colorer) SetEnabled(e bool)
- func (c *Colorer) White(s string) string
- func (c *Colorer) Yellow(s string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNoColorEnvSet ¶
func IsNoColorEnvSet() bool
IsNoColorEnvSet returns true if the NO_COLOR environment variable is set, regardless of its value. See https://no-color.org for more details.
func SetEnabled ¶
func SetEnabled(e bool)
SetEnabled sets whether color is enabled or disabled. Note that if NO_COLOR is set this will have no effect.
Types ¶
type Colorer ¶
type Colorer struct {
// contains filtered or unexported fields
}
Colorer allows for creating coloured strings. Using a Colorer instance allows for modifying certain attributes that affect output locally instead of globally, for example, disable colouring in a local context and not globally.
A zero value Colorer is a valid Colorer ready for use. Colors are enabled by default, unless NO_COLOR is set.
func (*Colorer) SetEnabled ¶
SetEnabled sets whether color is enabled or disabled. Note that if NO_COLOR is set this will have no effect.