colorstr

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
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

func Fprintf(w io.Writer, format string, a ...any) (n int, err error)

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

func Printf(format string, a ...any) (n int, err error)

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

func RequireEqualColorToken(t *testing.T, expectColorTokens string, actualString string)

RequireEqualColorToken compares whether the actual string is equal to the expected string after color processing.

func RequireNotEqualColorToken

func RequireNotEqualColorToken(t *testing.T, expectColorTokens string, actualString string)

RequireNotEqualColorToken compares whether the actual string is not equal to the expected string after color processing.

func Sprintf

func Sprintf(format string, a ...any) string

Sprintf is a convenience wrapper for fmt.Sprintf with support for color codes. Only color codes in the format param will be respected.

Types

This section is empty.

Jump to

Keyboard shortcuts

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