go: GChalk

https://github.com/jwalton/gchalk is a library heavily inspired by chalk, the popular Node.js terminal color library, and using go ports of supports-color and ansi-styles.


Feature Comparison

TTY Detection✅ (1)
Color Detection
Windows 10✅ (2)
Nested Styles✅ (3)
256 Color Support✅ (4)✅ (4)
16.7m Color Support
  1. fatih/color supports automatic TTY detection, but assumes that if stdout is not a TTY, then stderr is also not a TTY, which may not be true.
  2. fatih/color supports Windows 10, but you need to write to a special stream.
  3. aurora supports nested styles via its custom Sprintf(), but you can’t convert things to a string first – need to keep everything as aurora Values.
  4. aurora and mgutz/ansi both support 256 color output, but they don’t detect whether the terminal supports it or not, and won’t automatically convert 256 color output to 16 color output if it doesn’t.


package main

import (

func main() {
    fmt.Println(gchalk.Blue("This line is blue"))
    fmt.Println(gchalk.Blue("Hello") + " World" + gchalk.Red("!"))
    fmt.Println(gchalk.WithBlue().WithBgRed().Bold("Hello world!"))
    fmt.Println(gchalk.WithRGB(123, 45, 67).Underline("Underlined reddish color"))
    fmt.Println(gchalk.WihHex("#DEADED").Bold("Bold gray!"))
    fmt.Println(gchalk.StyleMust("blue")("Hello World!"))

    os.Stderr.WriteString(gchalk.Stderr.Red("Ohs noes!\n"))

    var error = gchalk.WithBold().Red
    var warning = gchalk.Yellow