Documentation
¶
Overview ¶
Package color provides utilities for colorizing terminal output using ANSI escape codes.
Index ¶
- Constants
- Variables
- func Black(v any) string
- func BlackBg(v any) string
- func Blue(v any) string
- func BlueBg(v any) string
- func BrightBlack(v any) string
- func BrightBlackBg(v any) string
- func BrightBlue(v any) string
- func BrightBlueBg(v any) string
- func BrightCyan(v any) string
- func BrightCyanBg(v any) string
- func BrightGreen(v any) string
- func BrightGreenBg(v any) string
- func BrightMagenta(v any) string
- func BrightMagentaBg(v any) string
- func BrightRed(v any) string
- func BrightRedBg(v any) string
- func BrightWhite(v any) string
- func BrightWhiteBg(v any) string
- func BrightYellow(v any) string
- func BrightYellowBg(v any) string
- func Cyan(v any) string
- func CyanBg(v any) string
- func Green(v any) string
- func GreenBg(v any) string
- func Magenta(v any) string
- func MagentaBg(v any) string
- func Red(v any) string
- func RedBg(v any) string
- func UnsafeString(b []byte) string
- func White(v any) string
- func WhiteBg(v any) string
- func Wrap(c Color, v any) string
- func Yellow(v any) string
- func YellowBg(v any) string
- type Color
Constants ¶
const ( // Escape is the escape character used to introduce ANSI escape sequences. Escape = "\x1b" // Prefix is the string that starts an ANSI escape sequence, indicating the beginning of formatting commands. Prefix = Escape + "[" // PrefixRGB is the prefix used for setting foreground colors using RGB values in ANSI escape sequences. PrefixRGB = Prefix + "38;2;" // PrefixBgRGB is the prefix used for setting background colors using RGB values in ANSI escape sequences. PrefixBgRGB = Prefix + "48;2;" // Reset is the ANSI escape sequence that resets all attributes (like color and formatting) in the terminal. Reset = Escape + "[0m" )
Variables ¶
var NoColor = isNoColor()
NoColor indicates whether colorization is disabled based on the NO_COLOR environment variable.
Functions ¶
func BrightBlack ¶ added in v0.2.0
BrightBlack returns a colorized string in bright black. (90)
func BrightBlackBg ¶ added in v0.2.0
BrightBlackBg returns a colorized string with a bright black background. (100)
func BrightBlue ¶ added in v0.2.0
BrightBlue returns a colorized string in bright blue. (94)
func BrightBlueBg ¶ added in v0.2.0
BrightBlueBg returns a colorized string with a bright blue background. (104)
func BrightCyan ¶ added in v0.2.0
BrightCyan returns a colorized string in bright cyan. (96)
func BrightCyanBg ¶ added in v0.2.0
BrightCyanBg returns a colorized string with a bright cyan background. (106)
func BrightGreen ¶ added in v0.2.0
BrightGreen returns a colorized string in bright green. (92)
func BrightGreenBg ¶ added in v0.2.0
BrightGreenBg returns a colorized string with a bright green background. (102)
func BrightMagenta ¶ added in v0.2.0
BrightMagenta returns a colorized string in bright magenta. (95)
func BrightMagentaBg ¶ added in v0.2.0
BrightMagentaBg returns a colorized string with a bright magenta background. (105)
func BrightRedBg ¶ added in v0.2.0
BrightRedBg returns a colorized string with a bright red background. (101)
func BrightWhite ¶ added in v0.2.0
BrightWhite returns a colorized string in bright white. (97)
func BrightWhiteBg ¶ added in v0.2.0
BrightWhiteBg returns a colorized string with a bright white background. (107)
func BrightYellow ¶ added in v0.2.0
BrightYellow returns a colorized string in bright yellow. (93)
func BrightYellowBg ¶ added in v0.2.0
BrightYellowBg returns a colorized string with a bright yellow background. (103)
func UnsafeString ¶
UnsafeString returns a unsafe string from a []byte
Types ¶
type Color ¶
type Color = string
Color represents an ANSI color code based on this [lookup table](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors).
const ( FgBlack Color = Escape + "[30m" FgRed Color = Escape + "[31m" FgGreen Color = Escape + "[32m" FgYellow Color = Escape + "[33m" FgBlue Color = Escape + "[34m" FgMagenta Color = Escape + "[35m" FgCyan Color = Escape + "[36m" FgWhite Color = Escape + "[37m" BgBlack Color = Escape + "[40m" BgRed Color = Escape + "[41m" BgGreen Color = Escape + "[42m" BgYellow Color = Escape + "[43m" BgBlue Color = Escape + "[44m" BgMagenta Color = Escape + "[45m" BgCyan Color = Escape + "[46m" BgWhite Color = Escape + "[47m" FgBrightBlack Color = Escape + "[90m" FgBrightRed Color = Escape + "[91m" FgBrightGreen Color = Escape + "[92m" FgBrightYellow Color = Escape + "[93m" FgBrightBlue Color = Escape + "[94m" FgBrightMagenta Color = Escape + "[95m" FgBrightCyan Color = Escape + "[96m" FgBrightWhite Color = Escape + "[97m" BgBrightBlack Color = Escape + "[100m" BgBrightRed Color = Escape + "[101m" BgBrightGreen Color = Escape + "[102m" BgBrightYellow Color = Escape + "[103m" BgBrightBlue Color = Escape + "[104m" BgBrightMagenta Color = Escape + "[105m" BgBrightCyan Color = Escape + "[106m" BgBrightWhite Color = Escape + "[107m" )