1
0
mirror of https://github.com/fatih/color.git synced 2024-11-24 08:02:14 +02:00
Color package for Go (golang)
Go to file
2014-02-17 23:50:55 -08:00
color_test.go Add helper Color functions 2014-02-17 23:46:20 -08:00
color.go Api and readme improvements 2014-02-17 23:50:55 -08:00
LICENSE.md Improve README and add examples to test. 2014-02-17 01:40:02 -08:00
README.md Api and readme improvements 2014-02-17 23:50:55 -08:00

Color GoDoc

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.")
color.Blue("Prints %s in blue.", "text") // a newline will be appended automatically

// Chain SGR paramaters
color.Green.Add(color.Bold).Println("Green with bold")
color.Red.Add(color.BgWhite, color.Underline).Println("Red with Black background and underscore")

Custom colors

// Create and reuse color objects
c := color.Cyan.Add(color.Underline)
c.Println("Prints cyan text with an underline.")
c.Printf("Thir prints bold cyan %s\n", "too!.")

// Create custom color objects:
d := color.New(color.FgWhite, color.BgGreen)
d.Println("White with green backround")

Plug into existing code

// Use handy standard colors.
color.Yellow.Set()
fmt.Println("Existing text in your codebase will be now in Yellow")
fmt.Printf("This one %s\n", "too")
color.Unset() // don't forget to unset

// You can set custom objects too
color.New(color.FgMagenta, color.Bold).Set()
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