Help us shape the future of Go! Take the 2026 Go Developer Survey

color

package
v1.20.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Black

func Black() support.Printer

func Blue

func Blue() support.Printer

func CaptureOutput

func CaptureOutput(f func(w io.Writer)) string

CaptureOutput simulates capturing of os.stdout with a buffer and returns what was written to the screen

func Cyan

func Cyan() support.Printer

func Debugf

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

func Debugln

func Debugln(a ...any)

func Default

func Default() support.Printer

func Disable

func Disable()

Disable disables color output

func Enable

func Enable()

Enable enables color output

func Errorf

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

func Errorln

func Errorln(a ...any)

func Gray

func Gray() support.Printer

func Green

func Green() support.Printer

func Infof

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

func Infoln

func Infoln(a ...any)

func Magenta

func Magenta() support.Printer

func New

func New(color Color) support.Printer

New Functions to create Printer with specific color

func Print

func Print(a ...any)

Print renders color tags and prints the provided arguments without a newline.

Example:

color.Print("<suc>Hello</>, <red>World</>")

func Printf

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

Printf formats a string with the provided arguments, renders color tags, and prints the result.

Example:

color.Printf("<red>Error:</> %s\n", err)

func Printfln

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

Printfln formats a string with the provided arguments, renders color tags, and prints the result with a newline.

Example:

color.Printfln("<success>Success:</> %s", message)

func Println

func Println(a ...any)

Println renders color tags and prints the provided arguments with a newline.

Example:

color.Println("<cyan>Welcome</>, <green>to</>, <yellow>Go</>")

func Red

func Red() support.Printer

func Sprint

func Sprint(a ...any) string

Sprint renders color tags and returns the formatted string.

Example:

result := color.Sprint("<blue>Processing...</>")

func Sprintf

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

Sprintf formats a string with the provided arguments, renders color tags, and returns the formatted result.

Example:

result := color.Sprintf("<red>Error:</> %s", err)

func Sprintfln

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

Sprintfln formats a string with the provided arguments, renders color tags, and returns the formatted result with a newline.

Example:

result := color.Sprintfln("<green>Task completed:</> %s", taskName)

func Sprintln

func Sprintln(a ...any) string

Sprintln renders color tags and returns the formatted string with a newline.

Example:

result := color.Sprintln("<fg=yellow;op=bold>Loading complete.</>")

func StripColor

func StripColor(s string) string

StripColor removes color tags and ANSI escape sequences, returning plain text.

func Successf

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

func Successln

func Successln(a ...any)

func Warnf

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

DEPRECATED: Use Warningf instead

func Warningf

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

func Warningln

func Warningln(a ...any)

func Warnln

func Warnln(a ...any)

DEPRECATED: Use Warningln instead

func White

func White() support.Printer

func Yellow

func Yellow() support.Printer

Types

type Color

type Color uint8
const (
	FgBlack Color = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
	// FgDefault revert default FG.
	FgDefault Color = 39
)
const (
	FgDarkGray Color = iota + 90
	FgLightRed
	FgLightGreen
	FgLightYellow
	FgLightBlue
	FgLightMagenta
	FgLightCyan
	FgLightWhite
	// FgGray is an alias of FgDarkGray.
	FgGray Color = 90
)

Extra foreground color 90 - 97.

func (Color) Print

func (c Color) Print(a ...any) *support.Printer

func (Color) Printf

func (c Color) Printf(format string, a ...any) *support.Printer

func (Color) Printfln

func (c Color) Printfln(format string, a ...any) *support.Printer

func (Color) Println

func (c Color) Println(a ...any) *support.Printer

func (Color) Sprint

func (c Color) Sprint(a ...any) string

func (Color) Sprintf

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

func (Color) Sprintfln

func (c Color) Sprintfln(format string, a ...any) string

func (Color) Sprintln

func (c Color) Sprintln(a ...any) string

Jump to

Keyboard shortcuts

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