colorize

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: Apache-2.0 Imports: 5 Imported by: 3

README

go-colorize

GoDoc Go Report Card

With:

$ go get github.com/soluble-ai/go-colorize

Go from this:

	Colorize("{info:[INFO]} {secondary:%s} {primary:%s}\n",
		time.Now().Format(time.RFC3339), "hello, world")

To this:

Screenshot

Default colors are:

Colors

Works with https://github.com/kyokomi/emoji and https://github.com/fatih/color.

Documentation

Overview

colorize does ANSI colored output and emoji substitution.

Colorize takes a fmt.Printf() template string and looks for styles in the format:

{style-name:text}

And inserts the color esacpe sequences around the text. It then passes the template off to emoji.Sprintf() from https://github.com/kyokomi/emoji.

It uses the color attribute names, color.Output, and color.NoColor from https://github.com/fatih/color.

The style names are modeled off the basic bootstrap color names.

Example use:

colorize.Colorize("{primary:We} want {bg-success:beer :beer:} and {warning:pizza} :pizza:")

Index

Constants

This section is empty.

Variables

View Source
var Styles = map[string]*Style{
	"primary":      NewStyle(color.FgCyan, color.Bold),
	"bg-primary":   NewStyle(color.FgHiWhite, color.BgCyan),
	"secondary":    NewStyle(color.FgHiBlack, color.Bold),
	"bg-secondary": NewStyle(color.FgHiWhite, color.BgHiBlack),
	"light":        NewStyle(color.FgHiBlack),
	"info":         NewStyle(color.FgBlue, color.Bold),
	"bg-info":      NewStyle(color.FgWhite, color.BgBlue),
	"success":      NewStyle(color.FgGreen),
	"bg-success":   NewStyle(color.FgHiWhite, color.BgGreen),
	"warning":      NewStyle(color.FgYellow),
	"bg-warning":   NewStyle(color.FgBlack, color.BgYellow),
	"danger":       NewStyle(color.FgHiRed),
	"bg-danger":    NewStyle(color.FgBlack, color.BgHiRed),
}

Styles maps style names to styles

Functions

func Colorize

func Colorize(template string, values ...interface{})

Colorize some text, printing the output to color.Output

func SColorize

func SColorize(template string, values ...interface{}) string

Colorize some text, returning a string

Types

type Style

type Style struct {
	// contains filtered or unexported fields
}

Style is a ANSI escape code sequence

func NewStyle

func NewStyle(attributes ...color.Attribute) *Style

NewStyle creates a style from a set of attributes

func (*Style) Enable

func (style *Style) Enable(val bool) *Style

Enable or disable this style

func (*Style) IsEnabled

func (style *Style) IsEnabled() bool

IsEnabled returns true if the style is enabled, either specifically to this style or globally via color.NoColor

Jump to

Keyboard shortcuts

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