colors

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enable

func Enable(enabler func() []Option)

Enable registers colorized options for pretty-printing the output of assertions.

The argument passed is a function that is executed after package initialization and CLI arg parsing.

This is not intended for concurrent use as it sets a package-level state.

func Enabled

func Enabled() bool

Enabled indicates if a global color options setting has been enabled.

func Options

func Options() *difflib.Options

Options returns the colorization options for difflib.

It yields nil if the colorization feature is not enabled (non blocking: colors just won't display).

Types

type Option

type Option func(o *options)

Option is a colorization option.

func WithDark

func WithDark() Option

WithDark sets the ThemeDark color theme.

func WithEnable

func WithEnable(enabled bool) Option

WithEnable enables colorized output.

func WithLight

func WithLight() Option

WithLight sets the ThemeLight color theme.

func WithSanitizedTheme

func WithSanitizedTheme(theme string) Option

WithSanitizedTheme sets a colorization theme from its name or does nothing if the theme is not supported.

func WithTheme

func WithTheme(theme Theme) Option

WithTheme sets a colorization theme.

type StringColorizer

type StringColorizer func(string) string

StringColorizer wraps a string with ANSI escape codes.

This is a simpler alternative to difflib.PrinterBuilder for cases where streaming to a bufio.Writer is not needed.

func ActualColorizer

func ActualColorizer() StringColorizer

ActualColorizer returns a colorizer for actual values.

It returns a no-op colorizer if colorization is not enabled.

func ExpectedColorizer

func ExpectedColorizer() StringColorizer

ExpectedColorizer returns a colorizer for expected values.

It returns a no-op colorizer if colorization is not enabled.

type Theme

type Theme string

Theme is a colorization theme for testify output.

const (
	// ThemeLight uses normal ANSI colors.
	ThemeLight Theme = "light"

	// ThemeDark uses bright ANSI colors.
	ThemeDark Theme = "dark"
)

func (Theme) String

func (t Theme) String() string

Jump to

Keyboard shortcuts

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