color

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvColor is the name of the environment variable allowing to
	// enable/disable coloring feature.
	EnvColor = "TESTDEEP_COLOR"
	// EnvColorTestName is the name of the environment variable
	// containing the color of test names in error reports.
	EnvColorTestName = "TESTDEEP_COLOR_TEST_NAME"
	// EnvColorTitle is the name of the environment variable
	// containing the color of failure reason in error reports.
	EnvColorTitle = "TESTDEEP_COLOR_TITLE"
	// EnvColorOK is the name of the environment variable
	// containing the color of "expected" in error reports.
	EnvColorOK = "TESTDEEP_COLOR_OK"
	// EnvColorBad is the name of the environment variable
	// containing the color of "got" in error reports.
	EnvColorBad = "TESTDEEP_COLOR_BAD"
)

Variables

View Source
var (
	// TestNameOn contains the ANSI color escape sequence to turn test
	// name color on.
	TestNameOn string
	// TestNameOff contains the ANSI color escape sequence to turn test
	// name color off.
	TestNameOff string
	// TitleOn contains the ANSI color escape sequence to turn title color on.
	TitleOn string
	// TitleOff contains the ANSI color escape sequence to turn title color off.
	TitleOff string
	// OKOn contains the ANSI color escape sequence to turn "expected" color on.
	OKOn string
	// OKOnBold contains the ANSI color escape sequence to turn
	// "expected" color and bold on.
	OKOnBold string
	// OKOff contains the ANSI color escape sequence to turn "expected" color off.
	OKOff string
	// BadOn contains the ANSI color escape sequence to turn "got" color on.
	BadOn string
	// BadOnBold contains the ANSI color escape sequence to turn "got"
	// color and bold on.
	BadOnBold string
	// BadOff contains the ANSI color escape sequence to turn "got" color off.
	BadOff string
)

Functions

func AppendTestNameOff

func AppendTestNameOff(b *strings.Builder)

AppendTestNameOff disables test name color in b.

func AppendTestNameOn

func AppendTestNameOn(b *strings.Builder)

AppendTestNameOn enables test name color in b.

func Bad

func Bad(s string, args ...any) string

Bad returns a string surrounded by BAD color. If len(args) is > 0, s and args are given to fmt.Sprintf.

Typically used in panic() when the user made a mistake.

func BadUsage

func BadUsage(usage string, param any, pos int, kind bool) string

BadUsage returns a string surrounded by BAD color to notice the user he passes a bad parameter to a function. Typically used in a panic().

func FromEnv

func FromEnv(env, defaultColor string) (string, string, string)

FromEnv returns the light, bold and end ANSI sequences for the color contained in the environment variable env. defaultColor is used if the environment variable does exist or is empty.

If coloring is disabled, returns "", "", "".

func Init

func Init()

Init initializes all the colors from the environment. It can be called several times concurrently, but only the first call is effective.

func On added in v1.13.0

func On() bool

On returns true if coloring feature is enabled.

func SaveState

func SaveState(on ...bool) func()

SaveState saves the "TESTDEEP_COLOR" environment variable value, sets it to "on" (if true passed as on) or "off" (if on not passed or set to false), resets the colors initialization and returns a function to be called in a defer statement. Only intended to be used in tests like:

defer color.SaveState()()

It is not thread-safe.

func TooManyParams

func TooManyParams(usage string) string

TooManyParams returns a string surrounded by BAD color to notice the user he called a variadic function with too many parameters. Typically used in a panic().

func UnBad added in v1.9.0

func UnBad(s string) string

UnBad returns s with bad color prefix & suffix removed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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