Documentation ¶
Overview ¶
Package color colorizes your terminal strings.
Default Brush are available in sub-package brush for your convenience. You can invoke them directly:
fmt.Printf("This is %s\n", brush.Red("red"))
...or you can create new ones!
weird := color.NewBrush(color.PurplePaint, color.CyanPaint) fmt.Printf("This color is %s\n", weird("weird"))
Create a Style, which has convenience methods :
redBg := color.NewStyle(color.RedPaint, color.YellowPaint)
Style.WithForeground or WithBackground returns a new Style, with the applied Paint. Styles are immutable so the original one is left unchanged :
greenFg := redBg.WithForeground(color.GreenPaint)
Style.Brush gives you a Brush that you can invoke directly to colorize strings :
green := greenFg.Brush() fmt.Printf("This is %s but not really\n", green("kind of green"))
You can use it with all sorts of things :
sout := log.New(os.Stdout, "["+brush.Green("OK").String()+"]\t", log.LstdFlags) serr := log.New(os.Stderr, "["+brush.Red("OMG").String()+"]\t", log.LstdFlags) sout.Printf("Everything was going %s until...", brush.Cyan("fine")) serr.Printf("%s killed %s !!!", brush.Red("Locke"), brush.Blue("Jacob"))
That's it!
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Paint ¶
type Paint string
Paint is a color to paint, either as a foreground or background paint
const ( BlackPaint Paint = `0;30` DarkRedPaint Paint = `0;31` DarkGreenPaint Paint = `0;32` DarkYellowPaint Paint = `0;33` DarkBluePaint Paint = `0;34` DarkPurplePaint Paint = `0;35` DarkCyanPaint Paint = `0;36` LightGrayPaint Paint = `0;37` DarkGrayPaint Paint = `1;30` RedPaint Paint = `1;31` GreenPaint Paint = `1;32` YellowPaint Paint = `1;33` BluePaint Paint = `1;34` PurplePaint Paint = `1;35` CyanPaint Paint = `1;36` WhitePaint Paint = `1;37` )
Valid colors for ANSI terminals
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style will give you colorized strings. Styles are immutable.
func NewStyle ¶
NewStyle gives you a style ready to produce strings with the given background and foreground colors
func (Style) Brush ¶
Brush is a function that can be used to color things directly, i.e:
red := NewStyle(BlackPaint, RedPaint).Brush() fmt.Printf("This is %s\n", red("red"))
func (Style) WithBackground ¶
WithBackground copies the current style and return a new Style that has the desired background. The original Style is unchanged and you must capture the return value.
func (Style) WithForeground ¶
WithForeground copies the current style and return a new Style that has the desired foreground. The original Style is unchanged and you must capture the return value.