termcolor

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ColorPrefix contains the ANSI control code prefix
	ColorPrefix = "\u001b["
	// ColorSuffix contains the ANSI control code suffix
	ColorSuffix = "m"

	// Reset contains the ANSI control code to reset the format
	Reset = ColorPrefix + "0" + ColorSuffix

	// Bold contains the ANSI control code to enable bold text
	Bold = "1" // Bold effect applies to text only (not background)

	// Underline contains the ANSI control code to enable underlined text
	Underline = "4" // Underline text

	// Reverse contains the ANSI control code to enable reverse text
	Reverse = "7" // Use reverse text (swap foreground and background)
)
View Source
var (
	// ColorPatterns contains the coloring rules
	ColorPatterns map[*regexp.Regexp]FieldStyle
)

Functions

func Bg

func Bg(hex string) string

Bg return ANSI color code for color "hex", applies to background

func ColorToAnsiIndex

func ColorToAnsiIndex(c uint8) uint8

ColorToAnsiIndex converts a uint8 color value (0-255) into an ANSI color value (0-5)

func Colorize

func Colorize(st Style, message string) string

Colorize applies style st to message, returning the colorized string

func ExpandStyle

func ExpandStyle(style string) string

ExpandStyle expands a style string into an ANSI control code

func Fg

func Fg(hex string) string

Fg returns ANSI color code for color "hex", applies to foreground

func GetColorPatterns

func GetColorPatterns() map[*regexp.Regexp]FieldStyle

GetColorPatterns loads the map used by the colorizer

func HexToColor256

func HexToColor256(hex string) uint8

HexToColor256 converts input "hex" into an ANSI color code (xterm-256) hex may be a set of 3 or 6 hexadecimal digits for RGB values

func HexToRgb

func HexToRgb(hex string) (r, g, b uint8)

HexToRgb converts a 3 or 6 digit hexadecimal string, representing RGB values, into separate R,G,B values

func HexToUint8

func HexToUint8(hexbyte string) uint8

HexToUint8 converts a hexadecimal string to a uint8

func RgbToColor256

func RgbToColor256(red, green, blue uint8) uint8

RgbToColor256 converts the red, green, blue tuple into an ANSI color code (xterm-256)

Types

type ColorizedWriter

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

ColorizedWriter provides an io.Writer which colorizes output

func NewColorizedWriter

func NewColorizedWriter(w io.Writer) ColorizedWriter

NewColorizedWriter returns a new io.Writer which implements coloring

func (ColorizedWriter) Write

func (me ColorizedWriter) Write(p []byte) (n int, err error)

type FieldSpec

type FieldSpec struct {
	KeyPattern   string
	ValuePattern string
}

FieldSpec defines a key/value pattern that the color patterns look for.

type FieldStyle

type FieldStyle struct {
	KeyStyle   Style
	ValueStyle Style
}

FieldStyle contains the styles for a particular output field

type Style

type Style string

Style contains a style spec for termcolor.Colorize()

Jump to

Keyboard shortcuts

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