color

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Colors = map[string]*Color{
	"Blue":    {Colorizer: termcolor.New(termcolor.FgBlue).Sprint},
	"Green":   {Colorizer: termcolor.New(termcolor.FgGreen).Sprint},
	"Yellow":  {Colorizer: termcolor.New(termcolor.FgYellow).Sprint},
	"Red":     {Colorizer: termcolor.New(termcolor.FgRed).Sprint},
	"BoldRed": {Colorizer: termcolor.New(termcolor.FgRed).Add(termcolor.Bold).Sprint},
	"Danger":  {Colorizer: termcolor.New(termcolor.FgBlack).Add(termcolor.Bold).Add(termcolor.BgRed).Sprint},
}

map Colors is the list of known colors. After adding a color here, be sure to add a key of the same name in muxytail.conf.

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 Sprint() method of a color from fatih/color
	Colorizer func(...any) string
}

struct Color holds the configuration for each handled termcolor.

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