prettyprint

package
v1.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package prettyprint contains tools for formatting text.

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func Colorize(msg string) string

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

func ColorizeVars(msg string, vars interface{}) string

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 DeisIfy

func DeisIfy(msg string) string

DeisIfy returns a pretty-printed deis logo along with the corresponding message

func Logo() string

Logo returns a colorized Deis logo with no space for text.

func NoColor

func NoColor(msg string) string

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

func Overwrite(msg string) string

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

func Overwritef(msg string, args ...interface{}) string

Overwritef formats a string and then returns an overwrite line.

See `Overwrite` for details.

func PrettyTabs

func PrettyTabs(msg map[string]string, spaces int) string

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: foo bar test testing

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL