Skip to content

Instantly share code, notes, and snippets.

@marians
Last active August 29, 2015 14:24
Show Gist options
  • Save marians/a31741e82d02718c03af to your computer and use it in GitHub Desktop.
Save marians/a31741e82d02718c03af to your computer and use it in GitHub Desktop.
Some colored terminal output using mgutz/ansi
package main
import (
"fmt"
"github.com/mgutz/ansi"
"github.com/ryanuber/columnize"
)
func main() {
config := columnize.DefaultConfig()
config.Delim = "|"
config.Glue = " "
config.Prefix = " "
colors := []string{"red", "green", "yellow", "blue", "magenta", "cyan", "white"}
flagsets := []string{"u", "b", "h", "ub", "uh", "bh"}
// Print some demo strings
lines := []string{}
for _, color := range colors {
line := ""
line += fmt.Sprint(ansi.Color(color, color)) + "|"
for _, flagset := range flagsets {
s := fmt.Sprintf("%s+%s", color, flagset)
line += fmt.Sprint(ansi.Color(s, s)) + "|"
}
line += fmt.Sprintln(ansi.ColorCode("reset"))
lines = append(lines, line)
}
result := columnize.Format(lines, config)
fmt.Println("")
fmt.Println(" This line shows text in default formatting for reference.")
fmt.Println("")
fmt.Println(result)
fmt.Println("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment