Documentation
¶
Index ¶
- type ColorScheme
- func (cs *ColorScheme) Black(s string) string
- func (cs *ColorScheme) Blue(s string) string
- func (cs *ColorScheme) Clone(opts ...ColorSchemeOption) *ColorScheme
- func (cs *ColorScheme) ColorFunc(style string) func(string) string
- func (cs *ColorScheme) Cyan(s string) string
- func (cs *ColorScheme) Green(s string) string
- func (cs *ColorScheme) LightBlack(s string) string
- func (cs *ColorScheme) LightBlue(s string) string
- func (cs *ColorScheme) LightCyan(s string) string
- func (cs *ColorScheme) LightGreen(s string) string
- func (cs *ColorScheme) LightMagenta(s string) string
- func (cs *ColorScheme) LightRed(s string) string
- func (cs *ColorScheme) LightWhite(s string) string
- func (cs *ColorScheme) LightYellow(s string) string
- func (cs *ColorScheme) Magenta(s string) string
- func (cs *ColorScheme) Red(s string) string
- func (cs *ColorScheme) White(s string) string
- func (cs *ColorScheme) Yellow(s string) string
- type ColorSchemeOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColorScheme ¶
type ColorScheme struct {
// contains filtered or unexported fields
}
ColorScheme formats text with different colors and styles.
Example ¶
fake := console.Fake() cs := colorscheme.New( colorscheme.WithTTY(fake.IsStdoutTTY), ) greeting := cs.ColorFunc("green") fmt.Fprintf(fake.Stdout(), "%s", greeting("Hello, world!")) stdout, _, _ := fake.Buffers() fmt.Println(stdout.String())
Output: Hello, world!
Example (Color) ¶
fake := console.Fake( console.WithStdoutTTY(true), ) cs := colorscheme.New( colorscheme.WithTTY(fake.IsStdoutTTY), ) greeting := cs.ColorFunc("green") fmt.Fprintf(fake.Stdout(), "%s", greeting("Hello, world!")) // Doubly escape fake stdout and write to real stdout to assert output. stdout, _, _ := fake.Buffers() s := strings.ReplaceAll(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) Black ¶ added in v0.3.0
func (cs *ColorScheme) Black(s string) string
func (*ColorScheme) Blue ¶ added in v0.3.0
func (cs *ColorScheme) Blue(s string) string
func (*ColorScheme) Clone ¶ added in v0.3.0
func (cs *ColorScheme) Clone(opts ...ColorSchemeOption) *ColorScheme
Clone returns a ColorScheme using the same color map, but can support different ColorSchemeOptions. You could use this, for example, to clone a Console's ColorScheme for Stderr, since the Console.ColorScheme() checks if Stdout is a TTY.
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.
func (*ColorScheme) Cyan ¶ added in v0.3.0
func (cs *ColorScheme) Cyan(s string) string
func (*ColorScheme) Green ¶ added in v0.3.0
func (cs *ColorScheme) Green(s string) string
func (*ColorScheme) LightBlack ¶ added in v0.3.0
func (cs *ColorScheme) LightBlack(s string) string
func (*ColorScheme) LightBlue ¶ added in v0.3.0
func (cs *ColorScheme) LightBlue(s string) string
func (*ColorScheme) LightCyan ¶ added in v0.3.0
func (cs *ColorScheme) LightCyan(s string) string
func (*ColorScheme) LightGreen ¶ added in v0.3.0
func (cs *ColorScheme) LightGreen(s string) string
func (*ColorScheme) LightMagenta ¶ added in v0.3.0
func (cs *ColorScheme) LightMagenta(s string) string
func (*ColorScheme) LightRed ¶ added in v0.3.0
func (cs *ColorScheme) LightRed(s string) string
func (*ColorScheme) LightWhite ¶ added in v0.3.0
func (cs *ColorScheme) LightWhite(s string) string
func (*ColorScheme) LightYellow ¶ added in v0.3.0
func (cs *ColorScheme) LightYellow(s string) string
func (*ColorScheme) Magenta ¶ added in v0.3.0
func (cs *ColorScheme) Magenta(s string) string
func (*ColorScheme) Red ¶ added in v0.3.0
func (cs *ColorScheme) Red(s string) string
func (*ColorScheme) White ¶ added in v0.3.0
func (cs *ColorScheme) White(s string) string
func (*ColorScheme) Yellow ¶ added in v0.3.0
func (cs *ColorScheme) Yellow(s string) string
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.
Click to show internal directories.
Click to hide internal directories.