One more Go library for using colors in the terminal console. The most important features are:
- ANSI colors support (using Escape Sequences)
- Multi-thread safe
- Support
FORCE_COLOR
,NO_COLOR
andTERM
variables out of the box - Super-lightweight and extremely fast
- Color codes are not pre-allocated, but cached (in memory) and re-used upon further usage
- Easy to integrate with the existing code-base
- Has no dependencies (except the standard library and
golang.org/x
)
package main
import (
"fmt"
"gh.tarampamp.am/colors"
)
func main() {
fmt.Println((colors.FgGreen | colors.Bold).Wrap("green color + bold text"))
var bg = colors.BgRed
fmt.Printf("%s red background %s\n", bg.Start(), bg.Reset())
colors.Enabled(false) // disable colors
colors.Enabled(true) // enable colors
}
For more examples see examples directory.