Categorygithub.com/gookit/color
modulepackage
1.5.4
Repository: https://github.com/gookit/color.git
Documentation: pkg.go.dev

# README

CLI Color

GitHub go.mod Go version Actions Status Codacy Badge GoDoc GitHub tag (latest SemVer) Build Status Coverage Status Go Report Card

A command-line color library with 16/256/True color support, universal API methods and Windows support.

中文说明

Basic color preview:

basic-color

Now, 256 colors and RGB colors have also been supported to work in Windows CMD and PowerShell:

color-on-cmd-pwsh

Features

  • Simple to use, zero dependencies
  • Supports rich color output: 16-color (4-bit), 256-color (8-bit), true color (24-bit, RGB)
    • 16-color output is the most commonly used and most widely supported, working on any Windows version
    • Since v1.2.4 the 256-color (8-bit), true color (24-bit) support windows CMD and PowerShell
    • See this gist for information on true color support
  • Support converts HEX HSL value to RGB color
  • Generic API methods: Print, Printf, Println, Sprint, Sprintf
  • Supports HTML tag-style color rendering, such as <green>message</> <fg=red;bg=blue>text</>.
    • In addition to using built-in tags, it also supports custom color attributes
    • Custom color attributes support the use of 16 color names, 256 color values, rgb color values and hex color values
    • Support working on Windows cmd and powerShell terminal
  • Basic colors: Bold, Black, White, Gray, Red, Green, Yellow, Blue, Magenta, Cyan
  • Additional styles: Info, Note, Light, Error, Danger, Notice, Success, Comment, Primary, Warning, Question, Secondary
  • Support by set NO_COLOR for disable color or use FORCE_COLOR for force open color render.
  • Support Rgb, 256, 16 color conversion

GoDoc

Install

go get github.com/gookit/color

Quick start

package main

import (
	"fmt"

	"github.com/gookit/color"
)

func main() {
	// quick use package func
	color.Redp("Simple to use color")
	color.Redln("Simple to use color")
	color.Greenp("Simple to use color\n")
	color.Cyanln("Simple to use color")
	color.Yellowln("Simple to use color")

	// quick use like fmt.Print*
	color.Red.Println("Simple to use color")
	color.Green.Print("Simple to use color\n")
	color.Cyan.Printf("Simple to use %s\n", "color")
	color.Yellow.Printf("Simple to use %s\n", "color")

	// use like func
	red := color.FgRed.Render
	green := color.FgGreen.Render
	fmt.Printf("%s line %s library\n", red("Command"), green("color"))

	// custom color
	color.New(color.FgWhite, color.BgBlack).Println("custom color style")

	// can also:
	color.Style{color.FgCyan, color.OpBold}.Println("custom color style")

	// internal theme/style:
	color.Info.Tips("message")
	color.Info.Prompt("message")
	color.Info.Println("message")
	color.Warn.Println("message")
	color.Error.Println("message")

	// use style tag
	color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>\n")
	// Custom label attr: Supports the use of 16 color names, 256 color values, rgb color values and hex color values
	color.Println("<fg=11aa23>he</><bg=120,35,156>llo</>, <fg=167;bg=232>wel</><fg=red>come</>")

	// apply a style tag
	color.Tag("info").Println("info style text")

	// prompt message
	color.Info.Prompt("prompt style message")
	color.Warn.Prompt("prompt style message")

	// tips message
	color.Info.Tips("tips style message")
	color.Warn.Tips("tips style message")
}

Run demo: go run ./_examples/demo.go

colored-out

Basic/16 color

Supported on any Windows version. Provide generic API methods: Print, Printf, Println, Sprint, Sprintf

color.Bold.Println("bold message")
color.Cyan.Println("yellow message")
color.Yellow.Println("yellow message")
color.Magenta.Println("yellow message")

// Only use foreground color
color.FgCyan.Printf("Simple to use %s\n", "color")
// Only use background color
color.BgRed.Printf("Simple to use %s\n", "color")

Run demo: go run ./_examples/color_16.go

basic-color

Custom build color

// Full custom: foreground, background, option
myStyle := color.New(color.FgWhite, color.BgBlack, color.OpBold)
myStyle.Println("custom color style")

// can also:
color.Style{color.FgCyan, color.OpBold}.Println("custom color style")

custom set console settings:

// set console color
color.Set(color.FgCyan)

// print message
fmt.Print("message")

// reset console settings
color.Reset()

Additional styles

provide generic API methods: Print, Printf, Println, Sprint, Sprintf

print message use defined style:

color.Info.Println("Info message")
color.Notice.Println("Notice message")
color.Error.Println("Error message")
// ...

Run demo: go run ./_examples/theme_basic.go

theme-basic

Tips style

color.Info.Tips("Info tips message")
color.Notice.Tips("Notice tips message")
color.Error.Tips("Error tips message")
color.Secondary.Tips("Secondary tips message")

Run demo: go run ./_examples/theme_tips.go

theme-tips

Prompt Style

color.Info.Prompt("Info prompt message")
color.Notice.Prompt("Notice prompt message")
color.Error.Prompt("Error prompt message")
// ...

Run demo: go run ./_examples/theme_prompt.go

theme-prompt

Block Style

color.Danger.Block("Danger block message")
color.Warn.Block("Warn block message")
// ...

Run demo: go run ./_examples/theme_block.go

theme-block

256-color usage

256 colors support Windows CMD, PowerShell environment after v1.2.4

Set the foreground or background color

  • color.C256(val uint8, isBg ...bool) Color256
c := color.C256(132) // fg color
c.Println("message")
c.Printf("format %s", "message")

c := color.C256(132, true) // bg color
c.Println("message")
c.Printf("format %s", "message")

256-color style

Can be used to set foreground and background colors at the same time.

  • S256(fgAndBg ...uint8) *Style256
s := color.S256(32, 203)
s.Println("message")
s.Printf("format %s", "message")

with options:

s := color.S256(32, 203)
s.SetOpts(color.Opts{color.OpBold})

s.Println("style with options")
s.Printf("style with %s\n", "options")

Run demo: go run ./_examples/color_256.go

color-tags

RGB/True color

RGB colors support Windows CMD, PowerShell environment after v1.2.4

Preview:

Run demo: Run demo: go run ./_examples/color_rgb.go

color-rgb

example:

color.RGB(30, 144, 255).Println("message. use RGB number")

color.HEX("#1976D2").Println("blue-darken")
color.HEX("#D50000", true).Println("red-accent. use HEX style")

color.RGBStyleFromString("213,0,0").Println("red-accent. use RGB number")
color.HEXStyle("eee", "D50000").Println("deep-purple color")

Set the foreground or background color

  • color.RGB(r, g, b uint8, isBg ...bool) RGBColor
c := color.RGB(30,144,255) // fg color
c.Println("message")
c.Printf("format %s", "message")

c := color.RGB(30,144,255, true) // bg color
c.Println("message")
c.Printf("format %s", "message")

Create a style from an hexadecimal color string:

  • color.HEX(hex string, isBg ...bool) RGBColor
c := color.HEX("ccc") // can also: "cccccc" "#cccccc"
c.Println("message")
c.Printf("format %s", "message")

c = color.HEX("aabbcc", true) // as bg color
c.Println("message")
c.Printf("format %s", "message")

RGB color style

Can be used to set the foreground and background colors at the same time.

  • color.NewRGBStyle(fg RGBColor, bg ...RGBColor) *RGBStyle
s := color.NewRGBStyle(RGB(20, 144, 234), RGB(234, 78, 23))
s.Println("message")
s.Printf("format %s", "message")

Create a style from an hexadecimal color string:

  • color.HEXStyle(fg string, bg ...string) *RGBStyle
s := color.HEXStyle("11aa23", "eee")
s.Println("message")
s.Printf("format %s", "message")

with options:

s := color.HEXStyle("11aa23", "eee")
s.SetOpts(color.Opts{color.OpBold})

s.Println("style with options")
s.Printf("style with %s\n", "options")

HTML-like tag usage

Print,Printf,Println functions support auto parse and render color tags.

	text := `
  <mga1>gookit/color:</>
     A <green>command-line</> 
     <cyan>color library</> with <fg=167;bg=232>256-color</>
     and <fg=11aa23;op=bold>True-color</> support,
     <fg=mga;op=i>universal API</> methods
     and <cyan>Windows</> support.
`
	color.Print(text)

Preview, code please see _examples/demo_tag.go:

demo_tag

Tag formats:

  • Use built in tags: <TAG_NAME>CONTENT</> e.g: <info>message</>
  • Custom tag attributes: <fg=VALUE;bg=VALUE;op=VALUES>CONTENT</> e.g: <fg=167;bg=232>wel</>

Supported on Windows cmd.exe PowerShell.

Examples:

// use style tag
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>")
color.Println("<suc>hello</>")
color.Println("<error>hello</>")
color.Println("<warning>hello</>")

// custom color attributes
color.Print("<fg=yellow;bg=black;op=underscore;>hello, welcome</>\n")

// Custom label attr: Supports the use of 16 color names, 256 color values, rgb color values and hex color values
color.Println("<fg=11aa23>he</><bg=120,35,156>llo</>, <fg=167;bg=232>wel</><fg=red>come</>")

Tag attributes

tag attributes format:

attr format:
 // VALUE please see var: FgColors, BgColors, AllOptions
 "fg=VALUE;bg=VALUE;op=VALUE"

16 color:
 "fg=yellow"
 "bg=red"
 "op=bold,underscore" // option is allow multi value
 "fg=white;bg=blue;op=bold"
 "fg=white;op=bold,underscore"

256 color:
 "fg=167"
 "fg=167;bg=23"
 "fg=167;bg=23;op=bold"
 
True color:
 // hex
 "fg=fc1cac"
 "fg=fc1cac;bg=c2c3c4"
 // r,g,b
 "fg=23,45,214"
 "fg=23,45,214;bg=109,99,88"

tag attributes parse please see func ParseCodeFromAttr()

Built-in tags

Built-in tags please see var colorTags in color_tag.go

// use style tag
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>")
color.Println("<suc>hello</>")
color.Println("<error>hello</>")

Run demo: go run ./_examples/color_tag.go

color-tags

Use color.Tag build message:

// set a style tag
color.Tag("info").Print("info style text")
color.Tag("info").Printf("%s style text", "info")
color.Tag("info").Println("info style text")

Color convert

Supports conversion between Rgb, 256, 16 colors, Rgb <=> 256 <=> 16

basic := color.Red
basic.Println("basic color")

c256 := color.Red.C256()
c256.Println("256 color")
c256.C16().Println("basic color")

rgb := color.Red.RGB()
rgb.Println("rgb color")
rgb.C256().Println("256 color")

Convert utils

color has many built-in color conversion utility functions.

func Basic2hex(val uint8) string

func Bg2Fg(val uint8) uint8
func Fg2Bg(val uint8) uint8

func C256ToRgb(val uint8) (rgb []uint8)
func C256ToRgbV1(val uint8) (rgb []uint8)

func Hex2basic(hex string, asBg ...bool) uint8
func Hex2rgb(hex string) []int
func HexToRGB(hex string) []int
func HexToRgb(hex string) (rgb []int)

func HslIntToRgb(h, s, l int) (rgb []uint8)
func HslToRgb(h, s, l float64) (rgb []uint8)
func HsvToRgb(h, s, v int) (rgb []uint8)

func Rgb2ansi(r, g, b uint8, isBg bool) uint8
func Rgb2basic(r, g, b uint8, isBg bool) uint8
func Rgb2hex(rgb []int) string
func Rgb2short(r, g, b uint8) uint8
func RgbTo256(r, g, b uint8) uint8
func RgbTo256Table() map[string]uint8
func RgbToAnsi(r, g, b uint8, isBg bool) uint8
func RgbToHex(rgb []int) string
func RgbToHsl(r, g, b uint8) []float64
func RgbToHslInt(r, g, b uint8) []int

Convert to RGBColor:

  • func RGBFromSlice(rgb []uint8, isBg ...bool) RGBColor
  • func RGBFromString(rgb string, isBg ...bool) RGBColor
  • func HEX(hex string, isBg ...bool) RGBColor
  • func HSL(h, s, l float64, isBg ...bool) RGBColor
  • func HSLInt(h, s, l int, isBg ...bool) RGBColor

Util functions

There are some useful functions reference

  • Disable() disable color render
  • SetOutput(io.Writer) custom set the colored text output writer
  • ForceOpenColor() force open color render
  • Colors2code(colors ...Color) string Convert colors to code. return like "32;45;3"
  • ClearCode(str string) string Use for clear color codes
  • ClearTag(s string) string clear all color html-tag for a string
  • IsConsole(w io.Writer) Determine whether w is one of stderr, stdout, stdin

More useful func please see https://pkg.go.dev/github.com/gookit/color

Detect color level

color automatically checks the color levels supported by the current environment.

// Level is the color level supported by a terminal.
type Level = terminfo.ColorLevel

// terminal color available level alias of the terminfo.ColorLevel*
const (
	LevelNo  = terminfo.ColorLevelNone     // not support color.
	Level16  = terminfo.ColorLevelBasic    // basic - 3/4 bit color supported
	Level256 = terminfo.ColorLevelHundreds // hundreds - 8-bit color supported
	LevelRgb = terminfo.ColorLevelMillions // millions - (24 bit)true color supported
)
  • func SupportColor() bool Whether the current environment supports color output
  • func Support256Color() bool Whether the current environment supports 256-color output
  • func SupportTrueColor() bool Whether the current environment supports (RGB)True-color output
  • func TermColorLevel() Level Get the currently supported color level

Projects using color

Check out these projects, which use https://github.com/gookit/color :

Gookit packages

  • gookit/ini Go config management, use INI files
  • gookit/rux Simple and fast request router for golang HTTP
  • gookit/gcli build CLI application, tool library, running CLI commands
  • gookit/slog Concise and extensible go log library
  • gookit/event Lightweight event manager and dispatcher implements by Go
  • gookit/cache Generic cache use and cache manager for golang. support File, Memory, Redis, Memcached.
  • gookit/config Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags
  • gookit/color A command-line color library with true color support, universal API methods and Windows support
  • gookit/filter Provide filtering, sanitizing, and conversion of golang data
  • gookit/validate Use for data validation and filtering. support Map, Struct, Form data
  • gookit/goutil Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more
  • More, please see https://github.com/gookit

See also

License

MIT

# Packages

Package colorp provide some functions for quick print colored text.

# Functions

AddStyle add a style.
AddTheme add a theme and style.
ApplyTag for messages.
Basic2hex convert basic color to hex string.
Basic2nameMap data.
BasicToHex convert basic color to hex string.
Bg2Fg bg color value to fg value.
Bit24 alias of the RGB().
Bit4 a method for create Color.
Bit8 create a color256.
Bluef print message with Blue color.
Blueln print message line with Blue color.
Bluep print message with Blue color.
C256 create a color256.
C256ToRgb convert an 256 color code to RGB numbers.
C256ToRgbV1 convert an 256 color code to RGB numbers refer https://github.com/torvalds/linux/commit/cec5b2a97a11ade56a701e83044d0a2a984c67b4.
ClearCode clear color codes.
ClearTag clear all tag for a string.
Colors2code convert colors to code.
Cyanf print message with Cyan color.
Cyanln print message line with Cyan color.
Cyanp print message with Cyan color.
DetectColorLevel for current env NOTICE: The method will detect terminal info each times, if only want to get current color level, please direct call SupportColor() or TermColorLevel().
Disable disable color output.
Errorf print message with Error style.
Errorln print message with Error style.
Errorp print message with Error color.
Fg2Bg fg color value to bg value.
ForceColor force open color render.
ForceOpenColor force open color render.
ForceSetColorLevel force open color render.
Fprint print rendered messages to writer Notice: will ignore print error.
Fprintf print format and rendered messages to writer.
Fprintln print rendered messages line to writer Notice: will ignore print error.
GetColorTags get all internal color tags.
GetStyle get defined style by name.
GetTagCode get color code by tag name.
GetTheme get defined theme by name.
Grayf print message with Gray color.
Grayln print message line with Gray color.
Grayp print message with Gray color.
Greenf print message with Green color.
Greenln print message line with Green color.
Greenp print message with Green color.
Hex alias of the HEX().
HEX create RGB color from a HEX color string.
Hex2basic convert hex string to basic color code.
Hex2rgb alias of the HexToRgb().
HEXStyle create a RGBStyle from HEX color string.
HexToRgb convert hex color string to RGB numbers Usage: rgb := HexToRgb("ccc") // rgb: [204 204 204] rgb := HexToRgb("aabbcc") // rgb: [170 187 204] rgb := HexToRgb("#aabbcc") // rgb: [170 187 204] rgb := HexToRgb("0xad99c0") // rgb: [170 187 204].
HexToRGB alias of the HexToRgb().
Hsl alias of the HSL().
HSL create RGB color from a hsl value.
HslInt alias of the HSLInt().
HSLInt create RGB color from a hsl int value.
HslIntToRgb Converts an HSL color value to RGB Assumes h: 0-360, s: 0-100, l: 0-100 returns r, g, and b in the set [0, 255].
HslToRgb Converts an HSL color value to RGB.
HsvToRgb Converts an HSL color value to RGB.
Infof print message with Info style.
Infoln print message with Info style.
Infop print message with Info color.
InnerErrs info.
IsConsole Determine whether w is one of stderr, stdout, stdin.
IsDefinedTag is defined tag name.
IsLikeInCmd check result Deprecated: please don't use.
IsMSys msys(MINGW64) environment, does not necessarily support color.
IsSupport16Color check current console is support color.
IsSupport256Color render check NOTICE: The method will detect terminal info each times, if only want to get current color level, please direct call SupportColor() or TermColorLevel().
IsSupportColor check current console is support color.
IsSupportRGBColor check.
IsSupportTrueColor render check.
IsTerminal returns true if the given file descriptor is a terminal.
IsWindows OS env.
Lprint passes colored messages to a log.Logger for printing.
Magentaf print message with Magenta color.
Magentaln print message line with Magenta color.
Magentap print message with Magenta color.
New create a custom style Usage: color.New(color.FgGreen).Print("message") equals to: color.Style{color.FgGreen}.Print("message").
NewDefaultScheme create an defuault color Scheme.
NewPrinter instance.
NewRGBStyle create a RGBStyle.
NewScheme create new Scheme.
NewTagParser create.
NewTheme instance.
NotRenderTag on call color.Xprint, color.PrintX.
ParseCodeFromAttr parse color attributes.
Print render color tag and print messages.
Printf format and print messages.
Println messages with new line.
Redf print message with Red color.
Redln print message line with Red color.
Redp print message with Red color.
Render parse color tags, return rendered string.
RenderCode render message by color code.
RenderString render a string with color code.
RenderWithSpaces Render code with spaces.
ReplaceTag parse string, replace color tag and return rendered string.
Reset reset console color attributes.
ResetOptions reset all package option setting.
ResetOutput reset output.
ResetTerminal terminal setting.
Rgb alias of the RGB().
RGB color create.
Rgb2ansi convert RGB-code to 16-code, alias of the RgbToAnsi().
Rgb2basic alias of the RgbToAnsi().
Rgb2hex alias of the RgbToHex().
Rgb2short convert RGB-code to 256-code.
RGBFromHEX quick RGBColor from hex string, alias of HEX().
RgbFromInt create instance from int r,g,b value.
RgbFromInts create instance from []int r,g,b value.
RGBFromSlice quick RGBColor from slice.
RGBFromString create RGB color from a string.
RGBStyleFromString create a RGBStyle from color value string.
RgbTo256 convert RGB-code to 256-code.
RgbTo256Table mapping data.
RgbToAnsi convert RGB-code to 16-code refer https://github.com/radareorg/radare2/blob/master/libr/cons/rgb.c#L249-L271.
RgbToHex convert RGB-code to hex-code Usage: hex := RgbToHex([]int{170, 187, 204}) // hex: "aabbcc".
RgbToHsl Converts an RGB color value to HSL.
RgbToHslInt Converts an RGB color value to HSL.
S256 create a color256 style Usage: s := color.S256() s := color.S256(132) // fg s := color.S256(132, 203) // fg and bg.
Set console color attributes.
SetOutput set default colored text output.
SetTerminal by given code.
Sprint parse color tags, return rendered string.
Sprintf format and return rendered string.
String alias of the ReplaceTag.
Successf print message with success style.
Successln print message with success style.
Successp print message with success color.
Support256Color Whether the current environment supports 256-color output.
SupportColor Whether the current environment supports color output.
SupportTrueColor Whether the current environment supports (RGB)True-color output.
TermColorLevel Get the currently supported color level.
Text alias of the ReplaceTag.
Warnf print message with Warn style.
Warnln print message with Warn style.
Warnp print message with Warn color.
WrapTag wrap a tag for a string "<tag>content</>".
Yellowf print message with Yellow color.
Yellowln print message line with Yellow color.
Yellowp print message with Yellow color.

# Constants

mark color is fg or bg.
mark color is fg or bg.
AttrExpr regex to match custom color attributes eg: "<fg=white;bg=blue;op=bold>content</>".
tpl for 8 bit 256 color(`2^8`) format: ESC[ … 38;5;<n> … m // 选择前景色 ESC[ … 48;5;<n> … m // 选择背景色 example: fg "\x1b[38;5;242m" bg "\x1b[48;5;208m" both "\x1b[38;5;242;48;5;208m" links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8位.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
Background colors.
Background colors.
Background colors.
Extra background color 100 - 107 (non-standard).
BgDefault revert default BG.
BgGray is alias of BgDarkGray.
Background colors.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
Extra background color 100 - 107 (non-standard).
Extra background color 100 - 107 (non-standard).
Extra background color 100 - 107 (non-standard).
Extra background color 100 - 107 (non-standard).
Extra background color 100 - 107 (non-standard).
Extra background color 100 - 107 (non-standard).
Extra background color 100 - 107 (non-standard).
Background colors.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
Background colors.
24 bit RGB color RGB: R 0-255 G 0-255 B 0-255 R 00-FF G 00-FF B 00-FF (16进制) Format: ESC[ … 38;2;<r>;<g>;<b> … m // Select RGB foreground color ESC[ … 48;2;<r>;<g>;<b> … m // Choose RGB background color links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#24位 example: fg: \x1b[38;2;30;144;255mMESSAGE\x1b[0m bg: \x1b[48;2;30;144;255mMESSAGE\x1b[0m both: \x1b[38;2;233;90;203;48;2;30;144;255mMESSAGE\x1b[0m.
Background colors.
BgBrown like yellow.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
CodeExpr regex to clear color codes eg "\033[1;36mText\x1b[0m".
CodeSuffix string for color code.
There are basic and light foreground color aliases.
DiffFgBg diff foreground and background color.
tpl for 8 bit 256 color(`2^8`) format: ESC[ … 38;5;<n> … m // 选择前景色 ESC[ … 48;5;<n> … m // 选择背景色 example: fg "\x1b[38;5;242m" bg "\x1b[48;5;208m" both "\x1b[38;5;242;48;5;208m" links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8位.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
Foreground colors.
Foreground colors.
青色.
亮黑(灰).
FgDefault revert default FG.
亮黑(灰).
Foreground colors.
Extra foreground color 90 - 97(非标准).
Extra foreground color 90 - 97(非标准).
Extra foreground color 90 - 97(非标准).
Extra foreground color 90 - 97(非标准).
Extra foreground color 90 - 97(非标准).
Extra foreground color 90 - 97(非标准).
Extra foreground color 90 - 97(非标准).
品红.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
Foreground colors.
24 bit RGB color RGB: R 0-255 G 0-255 B 0-255 R 00-FF G 00-FF B 00-FF (16进制) Format: ESC[ … 38;2;<r>;<g>;<b> … m // Select RGB foreground color ESC[ … 48;2;<r>;<g>;<b> … m // Choose RGB background color links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#24位 example: fg: \x1b[38;2;30;144;255mMESSAGE\x1b[0m bg: \x1b[48;2;30;144;255mMESSAGE\x1b[0m both: \x1b[38;2;233;90;203;48;2;30;144;255mMESSAGE\x1b[0m.
Foreground colors.
Foreground colors.
FullColorTpl for build color code.
is light Black.
There are basic and light foreground color aliases.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
Boundary value for foreground/background color 16 - base: fg 30~37, bg 40~47 - light: fg 90~97, bg 100~107.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
basic - 3/4 bit color supported.
hundreds - 8-bit color supported.
not support color.
millions - (24 bit)true color supported.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.
MatchExpr regex to match color tags Notice: golang 不支持反向引用.
There are basic and light foreground color aliases.
5 闪烁.
1 加粗.
8 隐匿的.
6 快速闪烁(未广泛支持).
2 模糊(不是所有的终端仿真器都支持).
3 斜体(不是所有的终端仿真器都支持).
0 重置所有设置.
7 颠倒的 交换背景色与前景色.
9 删除的,删除线(未广泛支持).
OptMax max option value.
4 下划线.
There are basic and light foreground color aliases.
ResetSet close all properties.
SettingTpl string.
StartSet chars.
StripExpr regex used for removing color tags StripExpr = `<[\/]?[a-zA-Z=;]+>` 随着上面的做一些调整.
tpl for 8 bit 256 color(`2^8`) format: ESC[ … 38;5;<n> … m // 选择前景色 ESC[ … 48;5;<n> … m // 选择背景色 example: fg "\x1b[38;5;242m" bg "\x1b[48;5;208m" both "\x1b[38;5;242;48;5;208m" links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8位.
24 bit RGB color RGB: R 0-255 G 0-255 B 0-255 R 00-FF G 00-FF B 00-FF (16进制) Format: ESC[ … 38;2;<r>;<g>;<b> … m // Select RGB foreground color ESC[ … 48;2;<r>;<g>;<b> … m // Choose RGB background color links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#24位 example: fg: \x1b[38;2;30;144;255mMESSAGE\x1b[0m bg: \x1b[48;2;30;144;255mMESSAGE\x1b[0m both: \x1b[38;2;233;90;203;48;2;30;144;255mMESSAGE\x1b[0m.
tpl for 8 bit 256 color(`2^8`) format: ESC[ … 38;5;<n> … m // 选择前景色 ESC[ … 48;5;<n> … m // 选择背景色 example: fg "\x1b[38;5;242m" bg "\x1b[48;5;208m" both "\x1b[38;5;242;48;5;208m" links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8位.
24 bit RGB color RGB: R 0-255 G 0-255 B 0-255 R 00-FF G 00-FF B 00-FF (16进制) Format: ESC[ … 38;2;<r>;<g>;<b> … m // Select RGB foreground color ESC[ … 48;2;<r>;<g>;<b> … m // Choose RGB background color links: https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#24位 example: fg: \x1b[38;2;30;144;255mMESSAGE\x1b[0m bg: \x1b[48;2;30;144;255mMESSAGE\x1b[0m both: \x1b[38;2;233;90;203;48;2;30;144;255mMESSAGE\x1b[0m.
There are basic and light foreground color aliases.
There are basic and light foreground color aliases.

# Variables

AllOptions color options map.
BgColors background colors map.
Comment color style.
Danger color style.
Debug color style.
Enable switch color render and display NOTICE: if ENV: NO_COLOR is not empty, will disable color render.
Error color style.
ExBgColors extra background colors map.
ExFgColors extra foreground colors map.
FgColors foreground colors map.
Info color style.
Light color style.
Note color style.
Notice color style.
Options color options map Deprecated: please use AllOptions instead.
Primary color style.
Question color style.
RenderTag render HTML tag on call color.Xprint, color.PrintX.
Secondary color style.
Styles internal defined styles, like bootstrap styles.
Success color style.
Themes internal defined themes.
Warn color style.

# Structs

Printer a generic color message printer.
RGBStyle supports set foreground and background color All are composed of 4 digits uint8, the first three digits are the color value; The last bit is different from RGBColor, here it indicates whether the value is set.
Scheme struct.
SimplePrinter use for quick use color print on inject to struct.
Style256 definition 前/背景色 都是由两位uint8组成, 第一位是色彩值; 第二位与 Bit8Color 不一样的是,在这里表示是否设置了值 0 未设置 !=0 已设置.
TagParser struct.
Theme definition.

# Interfaces

PrinterFace interface.

# Type aliases

Color Color16, 16 color value type 3(2^3=8) OR 4(2^4=16) bite color.
Color256 256 color (8 bit), uint8 range at 0 - 255.
Level is the color level supported by a terminal.
Opts basic color options.
RGBColor definition.
Style a 16 color style.
Tag value is a defined style name Usage: Tag("info").Println("message").