Documentation ¶
Overview ¶
Package prettyprint contains tools for formatting text.
Index ¶
- Variables
- func Colorize(msg string) string
- func ColorizeVars(msg string, vars interface{}) string
- func DeisIfy(msg string) string
- func Logo() string
- func NoColor(msg string) string
- func Overwrite(msg string) string
- func Overwritef(msg string, args ...interface{}) string
- func PrettyTabs(msg map[string]string, spaces int) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Colors = map[string]string{
"Default": "\033[0m",
"Black": "\033[0;30m",
"Red": "\033[0;31m",
"Green": "\033[0;32m",
"Yellow": "\033[0;33m",
"Blue": "\033[0;34m",
"Purple": "\033[0;35m",
"Cyan": "\033[0;36m",
"White": "\033[0;37m",
"BoldBlack": "\033[1;30m",
"BoldRed": "\033[1;31m",
"BoldGreen": "\033[1;32m",
"BoldYellow": "\033[1;33m",
"BoldBlue": "\033[1;34m",
"BoldPurple": "\033[1;35m",
"BoldCyan": "\033[1;36m",
"BoldWhite": "\033[1;37m",
"UnderBlack": "\033[4;30m",
"UnderRed": "\033[4;31m",
"UnderGreen": "\033[4;32m",
"UnderYellow": "\033[4;33m",
"UnderBlue": "\033[4;34m",
"UnderPurple": "\033[4;35m",
"UnderCyan": "\033[4;36m",
"UnderWhite": "\033[4;37m",
"HiBlack": "\033[30m",
"HiRed": "\033[31m",
"HiGreen": "\033[32m",
"HiYellow": "\033[33m",
"HiBlue": "\033[34m",
"HiPurple": "\033[35m",
"HiCyan": "\033[36m",
"HiWhite": "\033[37m",
"Deis1": "\033[31m● \033[34m▴ \033[32m■\033[0m",
"Deis2": "\033[32m■ \033[31m● \033[34m▴\033[0m",
"Deis3": "\033[34m▴ \033[32m■ \033[31m●\033[0m",
"Deis": "\033[31m● \033[34m▴ \033[32m■\n\033[32m■ \033[31m● \033[34m▴\n\033[34m▴ \033[32m■ \033[31m●\n",
}
Colors contains a map of the standard ANSI color codes.
There are four variants:
- Bare color names (Red, Black) color the characters.
- Bold color names add bolding to the characters.
- Under color names add underlining to the characters.
- Hi color names add highlighting (background colors).
These can be used within `text/template` to provide colors. The convenience function `Colorize()` provides this feature.
Functions ¶
func Colorize ¶
Colorize makes it easy to add colors to ANSI terminal output.
This takes any of the colors defined in the Colors map. Colors are rendered through the `text/template` system, so you may use pipes and functions as well.
Example:
Colorize("{{.Red}}ERROR:{{.Default}} Something happened.")
Example ¶
out := Colorize("{{.Red}}Hello {{.Default}}World{{.UnderGreen}}!{{.Default}}") fmt.Println(out)
Output:
func ColorizeVars ¶
ColorizeVars provides template rendering with color support.
The template is given a datum with two objects: `.V` and `.C`. `.V` contains the `vars` passed into the function. `.C` contains the color map.
Assuming `vars` contains a member named `Msg`, a template can be constructed like this:
{{.C.Red}}Message:{{.C.Default}} .V.Msg
Example ¶
vars := map[string]string{"Who": "World"} tpl := "{{.C.Red}}Hello {{.C.Default}}{{.V.Who}}!" out := ColorizeVars(tpl, vars) fmt.Println(out)
Output:
func NoColor ¶
NoColor strips colors from the template.
NoColor provides support for non-color ANSI terminals. It can be used as an alternative to Colorize when it is detected that the terminal does not support colors.
func Overwrite ¶
Overwrite sends a line that will be replaced by a subsequent overwrite.
Example:
Overwrite("foo") Overwrite("bar")
The above will print "foo" and then immediately replace it with "var".
(Interpretation of \r is left to the shell.)
func Overwritef ¶
Overwritef formats a string and then returns an overwrite line.
See `Overwrite` for details.
func PrettyTabs ¶
PrettyTabs formats a map with with alligned keys and values.
Example:
test := map[string]string { "test": "testing", "foo": "bar", }
Prettytabs(test, 5)
This will return a formatted string. The previous example would return: test testing foo bar
Types ¶
This section is empty.