color

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Colors = make(map[string]*Color)

map Colors is the list of known colors. Colors are added with AddColor(), and REs are added to that color with c.AddRE().

Functions

func Colorize added in v1.0.5

func Colorize(s string) string

Colorize iterates over each Color and applies all of the regexps associated with that color to the supplied string.

func ColorizeString added in v1.0.5

func ColorizeString(clr, s string) string

ColorizeString returns the string argument in a specific color.

Types

type Color

type Color struct {
	// RE is a slice of regexps that, when matched, are colorized
	RE []*regexp.Regexp
	// Colorizer is a function (generally from another package)
	// that returns a colorized version of its string arguments.
	Colorizer func(...any) string
}

struct Color holds the configuration for each handled termcolor.

func AddColor added in v1.2.0

func AddColor(s string) *Color

AddColor takes a color string, creates a renderer for it, and adds it to the Colors map. It returns the Color so that c.AddRE() can be chained.

func (*Color) AddRE

func (c *Color) AddRE(REs []string)

c.AddRE turns a slice of strings into regexps and attaches them to c.RE. Strings are surrounded by parentheses before being compiled into regexps.

func (*Color) Colorize

func (c *Color) Colorize(s string) string

c.Colorize applies c.Colorizer() for each regexp in c.RE to the provided string, and returns a string fully colorized for the particular termcolor.

Jump to

Keyboard shortcuts

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