Last active
August 29, 2015 14:24
-
-
Save marians/a31741e82d02718c03af to your computer and use it in GitHub Desktop.
Some colored terminal output using mgutz/ansi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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