It's a set of funcs and constants to provide basic colors to your terminal app.
Get it
go get github.com/unnamedxaer/colrz
Use it
package main
import (
"fmt"
c "github.com/unnamedxaer/colrz"
)
func main() {
// with method
fmt.Print(c.Yellow("\nThe tree is yellow."))
// with const
fmt.Printf("\n%sThe tree is red.%s", c.FgRed, c.FgReset)
// background color
fmt.Printf("\n%s", c.BlueBg(c.Yellow("The tree is green with blue leafs.")))
fmt.Printf("\n%s", c.WhiteBg(c.Green("The tree is green and ")+c.Yellow("yellow with white leafs.")))
fmt.Printf("\n%s", c.Yellow(c.MagentaBg("The tree is yellow ")+c.CyanBg(" with colorful leafs.")))
fmt.Printf("\n%s%sThe tree is %s yellow with %scolorful leafs.%s%s",
c.BgMagenta, c.FgYellow, c.BgCyan, c.FgBlack, c.BgReset, c.FgReset)
}
- Use colored text
fmt.Print(c.Red("The tree is red."))
- Use colored text on colored background
fmt.Printf("\n%s", c.BlueBg(c.Red("The tree is red with blue leafs.")))
If you set color via constant and do not reset it, then the color will persist for the next prints.
fmt.Printf("\n%sThe tree is red.", c.FgRed)
// ... some code
fmt.Printf("\ndone at %v", time.Now().Local())
// ... some code maybe more prints
// restore color to normal
fmt.Print(c.FgReset)
fmt.Print("\nThe winter is coming, the leaves have fallen.")
Colors may and will vary slightly depending on the terminals.
Not all terminals support this features eg. windows cmd / ps < 7.0
MIT. See the LICENSE file for more details.