mirror of
https://github.com/fatih/color.git
synced 2024-11-24 08:02:14 +02:00
Color package for Go (golang)
color_test.go | ||
color.go | ||
LICENSE.md | ||
README.md |
Color
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