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 ¶
- Variables
- func Fprintf(w io.Writer, format string, a ...any) (n int, err error)
- func Printf(format string, a ...any) (n int, err error)
- func RequireEqualColorToken(t *testing.T, expectColorTokens string, actualString string)
- func RequireNotEqualColorToken(t *testing.T, expectColorTokens string, actualString string)
- func Sprintf(format string, a ...any) string
Constants ¶
This section is empty.
Variables ¶
var DefaultTokens = (func() colorTokens { colors := make(map[string]string) for k, v := range colorstring.DefaultColors { colors[k] = v } return colorTokens{ Colorize: colorstring.Colorize{ Colors: colors, Disable: false, Reset: true, }, } })()
DefaultTokens uses default color tokens.
Functions ¶
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 RequireEqualColorToken ¶
RequireEqualColorToken compares whether the actual string is equal to the expected string after color processing.
func RequireNotEqualColorToken ¶
RequireNotEqualColorToken compares whether the actual string is not equal to the expected string after color processing.
Types ¶
This section is empty.