Documentation ¶
Overview ¶
Package color produces colored output in terms of ANSI Escape Codes. Posix and Windows platforms are supported.
Index ¶
- func Black(format string, a ...interface{})
- func BlackE(format string, a ...interface{})
- func BlackString(format string, a ...interface{}) string
- func Blue(format string, a ...interface{})
- func BlueE(format string, a ...interface{})
- func BlueString(format string, a ...interface{}) string
- func Cyan(format string, a ...interface{})
- func CyanE(format string, a ...interface{})
- func CyanString(format string, a ...interface{}) string
- func Disable(flag bool)
- func Enabled() bool
- func Green(format string, a ...interface{})
- func GreenE(format string, a ...interface{})
- func GreenString(format string, a ...interface{}) string
- func HiBlack(format string, a ...interface{})
- func HiBlackE(format string, a ...interface{})
- func HiBlackString(format string, a ...interface{}) string
- func HiBlue(format string, a ...interface{})
- func HiBlueE(format string, a ...interface{})
- func HiBlueString(format string, a ...interface{}) string
- func HiCyan(format string, a ...interface{})
- func HiCyanE(format string, a ...interface{})
- func HiCyanString(format string, a ...interface{}) string
- func HiGreen(format string, a ...interface{})
- func HiGreenE(format string, a ...interface{})
- func HiGreenString(format string, a ...interface{}) string
- func HiMagenta(format string, a ...interface{})
- func HiMagentaE(format string, a ...interface{})
- func HiMagentaString(format string, a ...interface{}) string
- func HiRed(format string, a ...interface{})
- func HiRedE(format string, a ...interface{})
- func HiRedString(format string, a ...interface{}) string
- func HiWhite(format string, a ...interface{})
- func HiWhiteE(format string, a ...interface{})
- func HiWhiteString(format string, a ...interface{}) string
- func HiYellow(format string, a ...interface{})
- func HiYellowE(format string, a ...interface{})
- func HiYellowString(format string, a ...interface{}) string
- func Magenta(format string, a ...interface{})
- func MagentaE(format string, a ...interface{})
- func MagentaString(format string, a ...interface{}) string
- func Red(format string, a ...interface{})
- func RedE(format string, a ...interface{})
- func RedString(format string, a ...interface{}) string
- func White(format string, a ...interface{})
- func WhiteE(format string, a ...interface{})
- func WhiteString(format string, a ...interface{}) string
- func Yellow(format string, a ...interface{})
- func YellowE(format string, a ...interface{})
- func YellowString(format string, a ...interface{}) string
- type Attribute
- type Color
- func (v Color) Sprint(a ...interface{}) string
- func (v Color) SprintFunc() func(a ...interface{}) string
- func (v Color) Sprintf(format string, a ...interface{}) string
- func (v Color) SprintfFunc() func(format string, a ...interface{}) string
- func (v Color) Sprintln(a ...interface{}) string
- func (v Color) SprintlnFunc() func(a ...interface{}) string
- type Console
- func (c *Console) DisableColors(strip bool)
- func (c *Console) Fd() uintptr
- func (c *Console) Print(col *Color, args ...string) (int, error)
- func (c *Console) PrintFunc(col *Color) func(a ...string)
- func (c *Console) Printf(col *Color, format string, args ...interface{}) (int, error)
- func (c *Console) PrintfFunc(col *Color) func(format string, args ...interface{})
- func (c *Console) Println(col *Color, args ...string) (int, error)
- func (c *Console) PrintlnFunc(col *Color) func(a ...string)
- func (c *Console) Set(color *Color)
- func (c *Console) Unset()
- func (c *Console) Write(b []byte) (int, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Black ¶
func Black(format string, a ...interface{})
Black helper to produce black text to stdout.
func BlackE ¶
func BlackE(format string, a ...interface{})
BlackE helper to produce black text to stderr.
func BlackString ¶
BlackString returns a string decorated with black attributes.
func BlueE ¶
func BlueE(format string, a ...interface{})
BlueE helper to produce blue text to stderr.
func BlueString ¶
BlueString returns a string decorated with blue attributes.
func CyanE ¶
func CyanE(format string, a ...interface{})
CyanE helper to produce cyan text to stderr.
func CyanString ¶
CyanString returns a string decorated with cyan attributes.
func Disable ¶ added in v0.0.5
func Disable(flag bool)
Disable is used to turn color output on and off globally.
func Enabled ¶ added in v0.0.5
func Enabled() bool
Enabled returns flag indicating whether colors are enabled or not.
func Green ¶
func Green(format string, a ...interface{})
Green helper to produce green text to stdout.
func GreenE ¶
func GreenE(format string, a ...interface{})
GreenE helper to produce green text to stderr.
func GreenString ¶
GreenString returns a string decorated with green attributes.
func HiBlack ¶
func HiBlack(format string, a ...interface{})
HiBlack helper to produce black text to stdout.
func HiBlackE ¶
func HiBlackE(format string, a ...interface{})
HiBlackE helper to produce black text to stderr.
func HiBlackString ¶
HiBlackString returns a high contrast black string.
func HiBlue ¶
func HiBlue(format string, a ...interface{})
HiBlue helper writes high contrast blue text to stdout.
func HiBlueE ¶
func HiBlueE(format string, a ...interface{})
HiBlueE helper writes high contrast blue text to stderr.
func HiBlueString ¶
HiBlueString returns a high contrast blue string.
func HiCyan ¶
func HiCyan(format string, a ...interface{})
HiCyan writes high contrast cyan colored text to stdout.
func HiCyanE ¶
func HiCyanE(format string, a ...interface{})
HiCyanE writes high contrast contrast cyan colored text to stderr.
func HiCyanString ¶
HiCyanString returns a high contrast cyan string.
func HiGreen ¶
func HiGreen(format string, a ...interface{})
HiGreen helper writes high contrast green text to stdout.
func HiGreenE ¶
func HiGreenE(format string, a ...interface{})
HiGreenE helper writes high contrast green text to stderr.
func HiGreenString ¶
HiGreenString returns a high contrast green string.
func HiMagenta ¶
func HiMagenta(format string, a ...interface{})
HiMagenta writes high contrast magenta text to stdout.
func HiMagentaE ¶
func HiMagentaE(format string, a ...interface{})
HiMagentaE writes high contrast magenta text to stderr.
func HiMagentaString ¶
HiMagentaString returns a high contrast magenta string.
func HiRed ¶
func HiRed(format string, a ...interface{})
HiRed helper to write high contrast red text to stdout.
func HiRedE ¶
func HiRedE(format string, a ...interface{})
HiRedE helper to write high contrast red text to stderr.
func HiRedString ¶
HiRedString returns a high contrast contrast black string.
func HiWhite ¶
func HiWhite(format string, a ...interface{})
HiWhite writes high contrast white colored text to stdout.
func HiWhiteE ¶
func HiWhiteE(format string, a ...interface{})
HiWhiteE writes high contrast white colored text to stderr.
func HiWhiteString ¶
HiWhiteString returns a high contrast white string.
func HiYellow ¶
func HiYellow(format string, a ...interface{})
HiYellow helper writes high contrast yellow text to stdout.
func HiYellowE ¶
func HiYellowE(format string, a ...interface{})
HiYellowE helper writes high contrast yellow text to stderr.
func HiYellowString ¶
HiYellowString returns a high contrast yellow string.
func Magenta ¶
func Magenta(format string, a ...interface{})
Magenta helper to produce magenta text to stdout.
func MagentaE ¶
func MagentaE(format string, a ...interface{})
MagentaE produces magenta text to stderr.
func MagentaString ¶
MagentaString returns a string decorated with magenta attributes.
func Red ¶
func Red(format string, a ...interface{})
Red helper to produce red text to stdout.
Example ¶
// Print some red text. Red("Hello red!")
Output:
func White ¶
func White(format string, a ...interface{})
White helper to produce white text to stdout.
func WhiteE ¶
func WhiteE(format string, a ...interface{})
WhiteE helper to produce white text to stderr.
func WhiteString ¶
WhiteString returns a string decorated with white attributes.
func Yellow ¶
func Yellow(format string, a ...interface{})
Yellow helper to produce yellow text to stdout.
func YellowE ¶
func YellowE(format string, a ...interface{})
YellowE helper to produce yellow text to stderr.
func YellowString ¶
YellowString returns a string decorated with yellow attributes.
Types ¶
type Attribute ¶
type Attribute uint64
Attribute defines a single SGR Code.
const ( Reset Attribute = 1 << iota Bold Faint Italic Underline BlinkSlow BlinkRapid ReverseVideo Concealed CrossedOut FgBlack FgRed FgGreen FgYellow FgBlue FgMagenta FgCyan FgWhite FgHiBlack FgHiRed FgHiGreen FgHiYellow FgHiBlue FgHiMagenta FgHiCyan FgHiWhite BgBlack BgRed BgGreen BgYellow BgBlue BgMagenta BgCyan BgWhite BgHiBlack BgHiRed BgHiGreen BgHiYellow BgHiBlue BgHiMagenta BgHiCyan BgHiWhite )
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color contains methods to create colored strings of text.
func (Color) Sprint ¶
Sprint returns text decorated with the display Attributes passed to Color constructor function.
func (Color) SprintFunc ¶
SprintFunc returns function that wraps Sprint.
Example ¶
// Create functions that add color information emphasized := New(FgRed, Bold, Underline).SprintFunc() fmt.Println("Wow, this is", emphasized("exciting!"))
Output:
func (Color) Sprintf ¶
Sprint formats according to the format specifier and returns text decorated with the display Attributes passed to Color constructor function.
func (Color) SprintfFunc ¶
SprintfFunc returns function that wraps Sprintf.
func (Color) Sprintln ¶
Sprint returns text decorated with the display Attributes and terminated by a line feed.
func (Color) SprintlnFunc ¶
SprintlnFunc returns function that wraps Sprintln.
type Console ¶
Console manages state for output, typically stdout or stderr.
func NewConsole ¶
NewConsole creates a wrapper around out which will output platform independent colored text.
func Stderr ¶
func Stderr() *Console
Stderr returns an io.Writer that writes colored text to standard error.
func Stdout ¶
func Stdout() *Console
Stdout returns an io.Writer that writes colored text to standard out.
func (*Console) DisableColors ¶
DisableColors if true ANSI color information will be removed for this console object. Passing true will enable colors for this Console, even if colors are disabled globally.
func (*Console) Print ¶
Print writes colored text to the console. The number of bytes written is returned.
func (*Console) Printf ¶
Printf formats according to a format specifier and writes colored text to the console.
func (*Console) PrintfFunc ¶
PrintfFunc returns a wrapper function for Printf.
func (*Console) Println ¶
Println writes colored text to console, appending input with a line feed. The number of bytes written is returned.
Example ¶
// Output underlined white text to stdout. clr := New(FgWhite, Underline) _, _ = Stdout().Println(clr, "I'm underlined and white!")
Output:
func (*Console) PrintlnFunc ¶
PrintlnFunc returns a wrapper function for Println.
func (*Console) Set ¶
Set will cause the color passed in as an argument to be written until Unset is called.