1
0
mirror of https://github.com/fatih/color.git synced 2025-02-16 18:34:39 +02:00
2014-02-18 01:05:57 -08:00
2014-02-18 01:03:13 -08:00
2014-02-18 00:20:24 -08:00
2014-02-18 01:01:28 -08:00
2014-02-18 01:05:57 -08:00
2014-02-18 01:03:13 -08:00

Color GoDoc Build Status

Color let you use colorized outputs in terms of ASCI Escape Codes. The API can be used in several way, pick one one that suits you.

Install

go get github.com/fatih/color

Examples

Standard colors

// Print with default helper functions
color.Cyan("Prints text in cyan.")

// a newline will be appended automatically
color.Blue("Prints %s in blue.", "text")

// These are using by default foreground colors.
color.Red("We have red")
color.Yellow("Yellow color too!")
color.Magenta("And many others ..")

Mix and reuse colors

// Create a new color object
c := color.New(color.FgCyan).Add(color.Underline)
c.Println("Prints cyan text with an underline.")

// Or just add them to New()
d := color.New(color.FgCyan, color.Bold)
d.Printf("This prints bold cyan %s\n", "too!.")


// Mix up foreground and background colors, create new mixes!
red := color.New(color.FgRed)

boldRed := red.Add(color.Bold)
boldRed.Println("This will print text in bold red.")

whiteBackground := red.Add(color.BgWhite)
whiteBackground.Println("Red text with White background.")

Plug into existing code

// Use handy standard colors.
color.Set(collor.FgYellow)

fmt.Println("Existing text will be now in Yellow")
fmt.Printf("This one %s\n", "too")

color.Unset() // don't forget to unset

// You can mix up parameters
color.Set(color.FgMagenta, color.Bold)
defer color.Unset() // use it in your function

fmt.Println("All text will be now bold magenta.")

Credits

License

The MIT License (MIT) - see LICENSE.md for more details

Description
Color package for Go (golang)
Readme 2.5 MiB
Languages
Go 100%