color

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 5 Imported by: 2

README

Color

Beaver comes with the color sub-package that can be used even without Beaver calls.

Color is an interface that simply needs Format(text string) string to fulfill it.
Any logger in beaver can be set to a Color.

Formatting a string with a single attribute

text := color.FgRed.Format("red")

Formatting a string with a full color

text := color.New(color.BgGreen, color.FgRed, color.Bold).Format("green background, red text, and bold")

Extended colors

Extended colors are 256-color extensions. They can be referred to by name, available in extended_colors.go.

True colors

True colors are full RBG colors, they can be either created with RGB values or parsed from hex.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Trace   = New(Bold, FgCyan)
	Debug   = New(Bold, FgBlue)
	Info    = New(Bold, FgGreen)
	Warn    = New(Bold, FgYellow)
	Error   = New(Bold, FgRed)
	Fatal   = New(Bold, BgRed)
	Default = New()
	Time    = Default
	Stack   = Default
)

Functions

This section is empty.

Types

type Basic

type Basic struct {
	Attrs []BasicAttribute
}

Basic defines a custom color object which is defined by SGR parameters.

func New

func New(attrs ...BasicAttribute) *Basic

New returns a new Color with attrs Attributes

func (*Basic) Add

func (b *Basic) Add(attrs ...BasicAttribute)

Add adds new Attributes to a Color

func (*Basic) Format

func (b *Basic) Format(text string) string

Format returns a string wrapped in the basic color

func (*Basic) Formatf added in v1.1.1

func (b *Basic) Formatf(format string, v ...interface{}) string

Formatf returns a formatted string wrapped in the basic color

func (*Basic) String

func (b *Basic) String() string

String returns a string representation of the sum of a Color's Attributes

type BasicAttribute

type BasicAttribute int

BasicAttribute defines a single SGR Code

const (
	Reset BasicAttribute = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)

Logger attributes

const (
	FgBlack BasicAttribute = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)

Foreground text colors

const (
	FgHiBlack BasicAttribute = iota + 90
	FgHiRed
	FgHiGreen
	FgHiYellow
	FgHiBlue
	FgHiMagenta
	FgHiCyan
	FgHiWhite
)

Foreground Hi-Intensity text colors

const (
	BgBlack BasicAttribute = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)

Background text colors

const (
	BgHiBlack BasicAttribute = iota + 100
	BgHiRed
	BgHiGreen
	BgHiYellow
	BgHiBlue
	BgHiMagenta
	BgHiCyan
	BgHiWhite
)

Background Hi-Intensity text colors

func (BasicAttribute) Format added in v1.1.1

func (a BasicAttribute) Format(text string) string

Format is a quick way to format a string using a single attribute

func (BasicAttribute) Formatf added in v1.1.1

func (a BasicAttribute) Formatf(text string, v ...interface{}) string

Format is a quick way to format a formatted string using a single attribute

type Color

type Color interface {
	Format(text string) string
	Formatf(text string, v ...interface{}) string
}

func ParseLevel

func ParseLevel(level string) Color

ParseLevel parses a string and returns a Beaver Level's Color, defaulting to Info

type Extended

type Extended struct {
	FG ExtendedAttribute
	BG ExtendedAttribute
}

Extended defines a custom color object which is defined by SGR parameters.

func NewExtended

func NewExtended(fg, bg ExtendedAttribute) *Extended

NewExtended returns a new Color with an ExtendedAttribute FG and BG

func (*Extended) Format

func (e *Extended) Format(text string) string

Format returns a string wrapped in the extended color

func (*Extended) Formatf added in v1.1.1

func (e *Extended) Formatf(text string, v ...interface{}) string

Formatf returns a formatted string wrapped in the extended color

func (*Extended) String

func (e *Extended) String() string

String returns a string representation of the sum of a Color's Attributes

type ExtendedAttribute

type ExtendedAttribute int

ExtendedAttribute defines an extended color

const (
	// #000000
	Black ExtendedAttribute = iota
	// #800000
	Maroon
	// #008000
	Green
	// #808000
	Olive
	// #000080
	Navy
	// #800080
	Purple
	// #008080
	Teal
	// #c0c0c0
	Silver
	// #808080
	Grey
	// #ff0000
	Red
	// #00ff00
	Lime
	// #ffff00
	Yellow
	// #0000ff
	Blue
	// #ff00ff
	Fuchsia
	// #00ffff
	Aqua
	// #ffffff
	White
	// #000000
	Grey0
	// #00005f
	NavyBlue
	// #000087
	DarkBlue
	// #0000af
	Blue3
	// #0000d7
	Blue3_1
	// #0000ff
	Blue1
	// #005f00
	DarkGreen
	// #005f5f
	DeepSkyBlue4
	// #005f87
	DeepSkyBlue4_1
	// #005faf
	DeepSkyBlue4_2
	// #005fd7
	DodgerBlue3
	// #005fff
	DodgerBlue2
	// #008700
	Green4
	// #00875f
	SpringGreen4
	// #008787
	Turquoise4
	// #0087af
	DeepSkyBlue3
	// #0087d7
	DeepSkyBlue3_1
	// #0087ff
	DodgerBlue1
	// #00af00
	Green3
	// #00af5f
	SpringGreen3
	// #00af87
	DarkCyan
	// #00afaf
	LightSeaGreen
	// #00afd7
	DeepSkyBlue2
	// #00afff
	DeepSkyBlue1
	// #00d700
	Green3_1
	// #00d75f
	SpringGreen3_1
	// #00d787
	SpringGreen2
	// #00d7af
	Cyan3
	// #00d7d7
	DarkTurquoise
	// #00d7ff
	Turquoise2
	// #00ff00
	Green1
	// #00ff5f
	SpringGreen2_1
	// #00ff87
	SpringGreen1
	// #00ffaf
	MediumSpringGreen
	// #00ffd7
	Cyan2
	// #00ffff
	Cyan1
	// #5f0000
	DarkRed
	// #5f005f
	DeepPink4
	// #5f0087
	Purple4
	// #5f00af
	Purple4_1
	// #5f00d7
	Purple3
	// #5f00ff
	BlueViolet
	// #5f5f00
	Orange4
	// #5f5f5f
	Grey37
	// #5f5f87
	MediumPurple4
	// #5f5faf
	SlateBlue3
	// #5f5fd7
	SlateBlue3_1
	// #5f5fff
	RoyalBlue1
	// #5f8700
	Chartreuse4
	// #5f875f
	DarkSeaGreen4
	// #5f8787
	PaleTurquoise4
	// #5f87af
	SteelBlue
	// #5f87d7
	SteelBlue3
	// #5f87ff
	CornflowerBlue
	// #5faf00
	Chartreuse3
	// #5faf5f
	DarkSeaGreen4_1
	// #5faf87
	CadetBlue
	// #5fafaf
	CadetBlue_1
	// #5fafd7
	SkyBlue3
	// #5fafff
	SteelBlue1
	// #5fd700
	Chartreuse3_1
	// #5fd75f
	PaleGreen3
	// #5fd787
	SeaGreen3
	// #5fd7af
	Aquamarine3
	// #5fd7d7
	MediumTurquoise
	// #5fd7ff
	SteelBlue1_1
	// #5fff00
	Chartreuse2
	// #5fff5f
	SeaGreen2
	// #5fff87
	SeaGreen1
	// #5fffaf
	SeaGreen1_1
	// #5fffd7
	Aquamarine1
	// #5fffff
	DarkSlateGray2
	// #870000
	DarkRed_1
	// #87005f
	DeepPink4_1
	// #870087
	DarkMagenta
	// #8700af
	DarkMagenta_1
	// #8700d7
	DarkViolet
	// #8700ff
	Purple_1
	// #875f00
	Orange4_1
	// #875f5f
	LightPink4
	// #875f87
	Plum4
	// #875faf
	MediumPurple3
	// #875fd7
	MediumPurple3_1
	// #875fff
	SlateBlue1
	// #878700
	Yellow4
	// #87875f
	Wheat4
	// #878787
	Grey53
	// #8787af
	LightSlateGrey
	// #8787d7
	MediumPurple
	// #8787ff
	LightSlateBlue
	// #87af00
	Yellow4_1
	// #87af5f
	DarkOliveGreen3
	// #87af87
	DarkSeaGreen
	// #87afaf
	LightSkyBlue3
	// #87afd7
	LightSkyBlue3_1
	// #87afff
	SkyBlue2
	// #87d700
	Chartreuse2_1
	// #87d75f
	DarkOliveGreen3_1
	// #87d787
	PaleGreen3_1
	// #87d7af
	DarkSeaGreen3
	// #87d7d7
	DarkSlateGray3
	// #87d7ff
	SkyBlue1
	// #87ff00
	Chartreuse1
	// #87ff5f
	LightGreen
	// #87ff87
	LightGreen_1
	// #87ffaf
	PaleGreen1
	// #87ffd7
	Aquamarine1_1
	// #87ffff
	DarkSlateGray1
	// #af0000
	Red3
	// #af005f
	DeepPink4_2
	// #af0087
	MediumVioletRed
	// #af00af
	Magenta3
	// #af00d7
	DarkViolet_1
	// #af00ff
	Purple_2
	// #af5f00
	DarkOrange3
	// #af5f5f
	IndianRed
	// #af5f87
	HotPink3
	// #af5faf
	MediumOrchid3
	// #af5fd7
	MediumOrchid
	// #af5fff
	MediumPurple2
	// #af8700
	DarkGoldenrod
	// #af875f
	LightSalmon3
	// #af8787
	RosyBrown
	// #af87af
	Grey63
	// #af87d7
	MediumPurple2_1
	// #af87ff
	MediumPurple1
	// #afaf00
	Gold3
	// #afaf5f
	DarkKhaki
	// #afaf87
	NavajoWhite3
	// #afafaf
	Grey69
	// #afafd7
	LightSteelBlue3
	// #afafff
	LightSteelBlue
	// #afd700
	Yellow3
	// #afd75f
	DarkOliveGreen3_2
	// #afd787
	DarkSeaGreen3_1
	// #afd7af
	DarkSeaGreen2
	// #afd7d7
	LightCyan3
	// #afd7ff
	LightSkyBlue1
	// #afff00
	GreenYellow
	// #afff5f
	DarkOliveGreen2
	// #afff87
	PaleGreen1_1
	// #afffaf
	DarkSeaGreen2_1
	// #afffd7
	DarkSeaGreen1
	// #afffff
	PaleTurquoise1
	// #d70000
	Red3_1
	// #d7005f
	DeepPink3
	// #d70087
	DeepPink3_1
	// #d700af
	Magenta3_1
	// #d700d7
	Magenta3_2
	// #d700ff
	Magenta2
	// #d75f00
	DarkOrange3_1
	// #d75f5f
	IndianRed_1
	// #d75f87
	HotPink3_1
	// #d75faf
	HotPink2
	// #d75fd7
	Orchid
	// #d75fff
	MediumOrchid1
	// #d78700
	Orange3
	// #d7875f
	LightSalmon3_1
	// #d78787
	LightPink3
	// #d787af
	Pink3
	// #d787d7
	Plum3
	// #d787ff
	Violet
	// #d7af00
	Gold3_1
	// #d7af5f
	LightGoldenrod3
	// #d7af87
	Tan
	// #d7afaf
	MistyRose3
	// #d7afd7
	Thistle3
	// #d7afff
	Plum2
	// #d7d700
	Yellow3_1
	// #d7d75f
	Khaki3
	// #d7d787
	LightGoldenrod2
	// #d7d7af
	LightYellow3
	// #d7d7d7
	Grey84
	// #d7d7ff
	LightSteelBlue1
	// #d7ff00
	Yellow2
	// #d7ff5f
	DarkOliveGreen1
	// #d7ff87
	DarkOliveGreen1_1
	// #d7ffaf
	DarkSeaGreen1_1
	// #d7ffd7
	Honeydew2
	// #d7ffff
	LightCyan1
	// #ff0000
	Red1
	// #ff005f
	DeepPink2
	// #ff0087
	DeepPink1
	// #ff00af
	DeepPink1_1
	// #ff00d7
	Magenta2_1
	// #ff00ff
	Magenta1
	// #ff5f00
	OrangeRed1
	// #ff5f5f
	IndianRed1
	// #ff5f87
	IndianRed1_1
	// #ff5faf
	HotPink
	// #ff5fd7
	HotPink_1
	// #ff5fff
	MediumOrchid1_1
	// #ff8700
	DarkOrange
	// #ff875f
	Salmon1
	// #ff8787
	LightCoral
	// #ff87af
	PaleVioletRed1
	// #ff87d7
	Orchid2
	// #ff87ff
	Orchid1
	// #ffaf00
	Orange1
	// #ffaf5f
	SandyBrown
	// #ffaf87
	LightSalmon1
	// #ffafaf
	LightPink1
	// #ffafd7
	Pink1
	// #ffafff
	Plum1
	// #ffd700
	Gold1
	// #ffd75f
	LightGoldenrod2_1
	// #ffd787
	LightGoldenrod2_2
	// #ffd7af
	NavajoWhite1
	// #ffd7d7
	MistyRose1
	// #ffd7ff
	Thistle1
	// #ffff00
	Yellow1
	// #ffff5f
	LightGoldenrod1
	// #ffff87
	Khaki1
	// #ffffaf
	Wheat1
	// #ffffd7
	Cornsilk1
	// #ffffff
	Grey100
	// #080808
	Grey3
	// #121212
	Grey7
	// #1c1c1c
	Grey11
	// #262626
	Grey15
	// #303030
	Grey19
	// #3a3a3a
	Grey23
	// #444444
	Grey27
	// #4e4e4e
	Grey30
	// #585858
	Grey35
	// #626262
	Grey39
	// #6c6c6c
	Grey42
	// #767676
	Grey46
	// #808080
	Grey50
	// #8a8a8a
	Grey54
	// #949494
	Grey58
	// #9e9e9e
	Grey62
	// #a8a8a8
	Grey66
	// #b2b2b2
	Grey70
	// #bcbcbc
	Grey74
	// #c6c6c6
	Grey78
	// #d0d0d0
	Grey82
	// #dadada
	Grey85
	// #e4e4e4
	Grey89
	// #eeeeee
	Grey93
)

type RGB

type RGB struct {
	Red   int
	Green int
	Blue  int
}

func MustParseHex

func MustParseHex(hexColor string) *RGB

func ParseHex

func ParseHex(hexColor string) (*RGB, error)

func (*RGB) String

func (r *RGB) String() string

String returns an r;g;b representation of an RGB

type True

type True struct {
	FG *RGB
	BG *RGB
}

func NewTrue

func NewTrue(fg, bg *RGB) *True

NewTrue returns a new Color with RGB FG and BG

func (*True) Format

func (t *True) Format(text string) string

Format returns a string wrapped in the true color

func (*True) Formatf added in v1.1.1

func (t *True) Formatf(text string, v ...interface{}) string

Formatf returns a formatted string wrapped in the true color

func (*True) String

func (t *True) String() string

String returns a string representation of the sum of a Color's Attributes

Jump to

Keyboard shortcuts

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