colorscheme

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Black

func Black(s string) string

func Blue

func Blue(s string) string

func Cyan

func Cyan(s string) string

func Green

func Green(s string) string

func LightBlack

func LightBlack(s string) string

func LightBlue

func LightBlue(s string) string

func LightCyan

func LightCyan(s string) string

func LightGreen

func LightGreen(s string) string

func LightMagenta

func LightMagenta(s string) string

func LightRed

func LightRed(s string) string

func LightWhite

func LightWhite(s string) string

func LightYellow

func LightYellow(s string) string

func Magenta

func Magenta(s string) string

func Red

func Red(s string) string

func White

func White(s string) string

func Yellow

func Yellow(s string) string

Types

type ColorScheme

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

ColorScheme formats text with different colors and styles.

Example
fake := console.Fake(
	console.WithStdoutTTY(true),
)

cs := colorscheme.New(
	colorscheme.WithTTY(fake.IsStdoutTTY),
)

greeting := cs.ColorFunc("green")
fmt.Fprintf(fake, "%s", greeting("Hello, world!"))

// Doubly escape fake stdout and write to real stdout to assert output.
s := strings.ReplaceAll(fake.Stdout().String(), "\x1b", `\x1b`)
fmt.Println(s)
Output:

\x1b[0;32mHello, world!\x1b[0m

func New

func New(opts ...ColorSchemeOption) *ColorScheme

New creates a new ColorScheme with options like WithTTY.

func (*ColorScheme) ColorFunc

func (cs *ColorScheme) ColorFunc(style string) func(string) string

ColorFunc returns a function to format text with a given style. The resulting function is cached to improve performance with subsequent use.

type ColorSchemeOption added in v0.2.0

type ColorSchemeOption func(*ColorScheme)

func WithTTY added in v0.2.0

func WithTTY(isTTY func() bool) ColorSchemeOption

WithTTY sets a function for ColorScheme to determine if the target Writer represents a TTY and avoid writing terminal sequences.

Jump to

Keyboard shortcuts

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