Documentation
¶
Overview ¶
Package colorstr interprets the input format containing color tokens like `[blue]hello [red]world` as the text "hello world" in two colors.
Just like tokens in the fmt package (e.g. '%s'), color tokens will only be effective when specified as the format parameter. Tokens not in the format parameter will not be interpreted.
colorstr.DefaultTokens.Printf("[blue]hello") ==> (a blue hello)
colorstr.DefaultTokens.Printf("[ahh]") ==> "[ahh]"
Color tokens in the Print arguments will never be interpreted. It can be useful to pass user inputs there.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultTokens = (func() colorTokens { colors := make(map[string]string) maps.Copy(colors, colorstring.DefaultColors) return colorTokens{ Colorize: colorstring.Colorize{ Colors: colors, Disable: false, Reset: true, }, } })()
DefaultTokens uses default color tokens.
Functions ¶
func ColorEnabled ¶ added in v1.16.5
func ColorEnabled() bool
ColorEnabled reports whether ANSI styling output is enabled globally.
func Fprintf ¶
Fprintf is a convenience wrapper for fmt.Fprintf with support for color codes. Only color codes in the format param will be respected.
func Printf ¶
Printf is a convenience wrapper for fmt.Printf with support for color codes. Only color codes in the format param will be respected.
func SetColorEnabled ¶ added in v1.16.5
func SetColorEnabled(enabled bool)
SetColorEnabled sets whether ANSI styling output is enabled globally.
This matches the behavior of common CLI color libraries (e.g. github.com/fatih/color): the decision is made once and then reused across all output.
Types ¶
This section is empty.