color

package
v0.0.0-...-3fb1d06 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package color provides functions for creating colored strings.

There are several functions provided to make it easy to set foreground colors.

// creates a string with a red foreground color
color.Red("uh oh")

Colors can be globally enabled or disabled by using SetEnabled. If you wish to control colors in a local scope and not affect the global state, create a Colorer instance.

var c color.Colorer
// Disable colors only for this Colorer
c.SetEnabled(false)
s := c.Red("uh oh") // Will not be colored

This package also supports the NO_COLOR environment variable. If NO_COLOR is set with any value, colors will be disabled. See https://no-color.org for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Black

func Black(s string) string

Black creates a black colored string.

func Blue

func Blue(s string) string

Blue creates a blue colored string.

func Cyan

func Cyan(s string) string

Cyan creates a cyan colored string.

func Green

func Green(s string) string

Green creates a green colored string.

func IsNoColorEnvSet

func IsNoColorEnvSet() bool

IsNoColorEnvSet returns true if the NO_COLOR environment variable is set, regardless of its value. See https://no-color.org for more details.

func Magenta

func Magenta(s string) string

Magenta creates a magenta colored string.

func Red

func Red(s string) string

Red creates a red colored string.

func SetEnabled

func SetEnabled(e bool)

SetEnabled sets whether color is enabled or disabled. Note that if NO_COLOR is set this will have no effect.

func White

func White(s string) string

White creates a white colored string.

func Yellow

func Yellow(s string) string

Yellow creates a yellow colored string.

Types

type Colorer

type Colorer struct {
	// contains filtered or unexported fields
}

Colorer allows for creating coloured strings. Using a Colorer instance allows for modifying certain attributes that affect output locally instead of globally, for example, disable colouring in a local context and not globally.

A zero value Colorer is a valid Colorer ready for use. Colors are enabled by default, unless NO_COLOR is set.

func (*Colorer) Black

func (c *Colorer) Black(s string) string

Black creates a black colored string.

func (*Colorer) Blue

func (c *Colorer) Blue(s string) string

Blue creates a blue colored string.

func (*Colorer) Cyan

func (c *Colorer) Cyan(s string) string

Cyan creates a cyan colored string.

func (*Colorer) Green

func (c *Colorer) Green(s string) string

Green creates a green colored string.

func (*Colorer) Magenta

func (c *Colorer) Magenta(s string) string

Magenta creates a magenta colored string.

func (*Colorer) Red

func (c *Colorer) Red(s string) string

Red creates a red colored string.

func (*Colorer) SetEnabled

func (c *Colorer) SetEnabled(e bool)

SetEnabled sets whether color is enabled or disabled. Note that if NO_COLOR is set this will have no effect.

func (*Colorer) White

func (c *Colorer) White(s string) string

White creates a white colored string.

func (*Colorer) Yellow

func (c *Colorer) Yellow(s string) string

Yellow creates a yellow colored string.

Jump to

Keyboard shortcuts

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