term

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//Reset     = []byte("\x1b[0m")
	ResetFG   = []byte("\033[0;00m")
	Bold      = []byte("\x1b[1m")
	Dim       = []byte("\x1b[2m")
	Italic    = []byte("\x1b[3m")
	Underline = []byte("\x1b[4m")
	Blink     = []byte("\x1b[5m")
	Reverse   = []byte("\x1b[7m")
	Hidden    = []byte("\x1b[8m")
)
View Source
var (
	// ColorOut is a io.Writer that writes to os.Stdout
	// while substituting the the color escapes in it's input.
	//
	// See Interpret for a description of color escapes.
	ColorOut io.Writer = NewInterpretingWriter(os.Stdout)
	// ColorErr is a io.Writer that writes to os.Stderr
	// while substituting the the color escapes in it's input.
	//
	// See Interpret for a description of color escapes.
	ColorErr io.Writer = NewInterpretingWriter(os.Stderr)
)
View Source
var (
	Before = before
	After  = after
)
View Source
var (
	Fc    = fgcolors
	Bc    = bgcolors
	Rgb   = &rgbControl{}
	Reset = reset
)
View Source
var MaxEscapeCodeLen uint = 15

MaxEscapeCodeLen is the maximum number of bytes that the contents of an escape code may be. If the escape code is longer than this, it is output verbatim without being replaced. If MaxEscapeCodeLen is set to 0 escape codes may be any length (checking is not performed)

This is used to avoid a possible denial of service.

Functions

func BGColorLookUp

func BGColorLookUp(val uint8) []byte

func BgByte

func BgByte(in byte, r, g, b uint8) []byte

BgByte colorizes the background of the input with the terminal color that matches the closest the RGB color.

func BgBytes

func BgBytes(in []byte, r, g, b uint8) []byte

BgBytes colorizes the background of the input with the terminal color that matches the closest the RGB color.

func BgHex

func BgHex(in, hex string) string

func BgShift

func BgShift(in, from string, h, l, s float64) string

func BgString

func BgString(in string, r, g, b uint8) string

BgString colorizes the background of the input with the terminal color that matches the closest the RGB color.

This is simply a helper for Bytes.

func Bytes

func Bytes(in []byte, fr, fg, fb, br, bg, bb uint8) []byte

Bytes colorizes the input with the terminal color that matches the closest the RGB color.

func Exec

func Exec(cmd string, dir string) (out chan string, err error)

func FGColorLookUp

func FGColorLookUp(val uint8) []byte

func FgByte

func FgByte(in byte, r, g, b uint8) []byte

Byte colorizes the input with the terminal color that matches the closest the RGB color.

func FgBytes

func FgBytes(in []byte, r, g, b uint8) []byte

Bytes colorizes the foreground with the terminal color that matches the closest the RGB color.

func FgHex

func FgHex(in, hex string) string

func FgShift

func FgShift(in, from string, h, l, s float64) string

func FgString

func FgString(in string, r, g, b uint8) string

FgString colorizes the foreground of the input with the terminal color that matches the closest the RGB color.

This is simply a helper for Bytes.

func GetColor

func GetColor(r, g, b uint8, foreground bool) []byte

func HSLtoRGB

func HSLtoRGB(h, s, l float64) (r, g, b uint8)

HSLtoRGB is a helper that transforms 8bits RGB colors to 8bits HSL colors.

func Hex

func Hex(hex string) []byte

func HexToRGB

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

func Interpret

func Interpret(r io.ByteReader, w io.Writer) error

Interpret reads data from r and writes it to w, while substituting the color escapes in the input.

Color escapes are directives having one of forms on the following lines:

{#RRGGBB}
{#RRGGBB,#RRGGBB}
{,#RRGGBB}
{}

The first form sets the terminal foreground color to the color RR,GG,BB where RR is the red component, GG green and BB blue. Each component is in hex.

The second form sets the foreground and background colors, while the third sets only the background.

The fourth form resets the terminal colors to defaults.

To output a literal { character, use two braces: {{.

func InterpretStr

func InterpretStr(s string) string

ColorizeTemplate substitutes the color escapes in the string s and returns the resulting string.

See Interpret for a description of color escapes.

func Printf

func Printf(w io.Writer, format string, v ...interface{})

func Println

func Println(format string, v ...interface{})

func RGBtoHSL

func RGBtoHSL(r, g, b uint8) (h, s, l float64)

RGBtoHSL is a helper that transforms 8bits HSL colors to 8bits RGB colors.

func RandomHSL

func RandomHSL() (h, s, l float64)

func RandomHex

func RandomHex() string

func RandomRGB

func RandomRGB() (r, g, b uint8)

func Sprintf

func Sprintf(format string, v ...interface{}) string

func String

func String(in string, fr, fg, fb, br, bg, bb uint8) string

String colorizes the input with the terminal color that matches the closest the RGB color.

This is simply a helper for Bytes.

func Stylize

func Stylize(in []byte, format ...[]byte) (res []byte)

Types

type Fmt

type Fmt struct {
}

type InterpretingWriter

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

ColorTemplateWriter writes to an underlying io.Writer while substituting the color escapes in the input.

See Interpret for a description of color escapes.

func NewInterpretingWriter

func NewInterpretingWriter(w io.Writer) InterpretingWriter

NewColorTemplateWriter creates a ColorTemplateWriter that writes to w while substituting the color escapes in the input.

See Interpret for a description of color escapes.

func (InterpretingWriter) Write

func (tw InterpretingWriter) Write(p []byte) (n int, err error)

Write writes to the underlying io.Writer while substituting the color escapes in the input.

See Interpret for a description of color escapes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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