#Gocolorize
Gocolorize is a package that allows Go programs to provide ANSI coloring in a stateful manner. Gocolorize is ideal for logging or cli applications.
##Features
- Stateful ANSI coloring
- Supports Foreground and background colors
- Supports a nuber of text properties such as bold or underline
- Color multiple arguments
- Color multiple interfaces, including complex types
- Tests with 100% coverage
- Working examples
- Disable ability for portability
##Install Gocolorize
To install:
$ go get github.com/agtorre/gocolorize
##Usage
Ways to initialize a Colorize object:
var c gocolorize.Colorize
c.SetFg(gocolorize.Red)
c.SetBg(gocolorize.Black)
c := gocolorize.Colorize{Fg: gocolorize.Red, Bg: gocolorize.Black}
c := gocolorize.NewColor("red:black")
Once you have an object:
c.Paint("This", "accepts", "multiple", "arguments", "and", "types:", 1, 1.25, "etc")
p = c.Paint
p("Neat")
Fmt.Println(p("test"))
a := "test " + p("case")
p = c.Paint
c.SetFg(gocolorize.Green)
p2 = c.Paint
Fmt.Println(p("different" + " " + p2("colors")))
Object Properties:
c.ToggleFgIntensity()
c.ToggleBgIntensity()
c.ToggleBold()
c.ToggleBlink()
c.ToggleUnderLine()
c.ToggleInverse()
gocolorize.SetPlain(true)
##NewColor String Format
"foregroundColor+attributes:backgroundColor+attributes"
Colors:
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
Attributes:
- b = bold foreground
- B = blink foreground
- u = underline foreground
- h = high intensity (bright) foreground, background
- i = inverse
##Examples
See examples directory for examples:
$ cd examples/
$ go run song.go
$ go run logging.go
##Tests
Tests are another good place to see examples. In order to run tests:
$ go test -cover
##Portability
ANSI coloring will not work in default Windows environments and may not work in other environments correctly. In order to allow compatibility with these environments, you can call:
gocolorize.SetPlain(true)
Once toggled, the library will still function, but it will not color the output.
References
Wikipedia ANSI escape codes Colors
A stylesheet author's guide to terminal colors
Special Thanks
https://github.com/mgutz/ansi was an inspiration for the latest version. I did a lot of rewriting, removed the 'paints' module, and did a lot of general cleanup. I learned a lot reading this and using this code.