Documentation
¶
Index ¶
- Constants
- Variables
- func AddStyle(name string, s Style)
- func AddTheme(name string, style Style)
- func ClearCode(str string) string
- func RenderCode(code string, args ...interface{}) string
- func RenderStr(code string, str string) string
- func Reset() (int, error)
- func Set(colors ...Color) (int, error)
- type Color
- type Style
- type Theme
Constants ¶
View Source
const ( Red = FgRed Cyan = FgCyan Gray = FgDarkGray // is light Black Blue = FgBlue Black = FgBlack Green = FgGreen White = FgWhite Yellow = FgYellow Magenta = FgMagenta Bold = OpBold Normal = FgDefault LightRed = FgLightRed LightCyan = FgLightCyan LightBlue = FgLightBlue LightGreen = FgLightGreen LightWhite = FgLightWhite LightYellow = FgLightYellow LightMagenta = FgLightMagenta )
There are basic and light foreground color aliases
View Source
const ( TplShowColor = "\x1b[%sm%s\x1b[0m" // 颜色模板 TplColorSet = "\x1b[%sm" TplResetSet = "\x1b[0m" // 重置/正常 关闭所有属性。 CodeExpr = `\033\[[\d;?]+m` // 清理颜色代码正则, 例如 "\033[1;36mText\x1b[0m" )
Variables ¶
View Source
var ( // Trace color style Trace = &Theme{"trace", Style{OpReset, FgBlue}} // Debug color style Debug = &Theme{"debug", Style{OpReset, FgDefault}} // Info color style Info = &Theme{"info", Style{OpReset, FgCyan}} // Warn color style Warn = &Theme{"warn", Style{OpBold, FgYellow}} // Error color style Error = &Theme{"error", Style{OpBold, FgRed}} // Question color style Question = &Theme{"question", Style{OpBold, FgMagenta}} // Success color style Success = &Theme{"success", Style{OpBold, FgGreen}} // Danger color style Fatal = &Theme{"danger", Style{FgLightWhite, BgRed}} // Primary color style Primary = &Theme{"primary", Style{OpReset, FgLightBlue}} // Secondary color style Comment = &Theme{"secondary", Style{OpReset, FgDarkGray}} // Note color style Note = &Theme{"note", Style{OpBold, FgLightCyan}} )
internal themes(like bootstrap style) Usage:
color.Info.Print("message")
color.Info.Printf("a %s message", "test")
color.Warn.Println("message")
color.Error.Println("message")
View Source
var BgColors = map[string]Color{ "black": BgBlack, "red": BgRed, "green": BgGreen, "yellow": BgYellow, "blue": BgBlue, "magenta": BgMagenta, "cyan": BgCyan, "white": BgWhite, "default": BgDefault, }
BgColors background colors map
View Source
var ExBgColors = map[string]Color{ "darkGray": BgDarkGray, "lightRed": BgLightRed, "lightGreen": BgLightGreen, "lightYellow": BgLightYellow, "lightBlue": BgLightBlue, "lightMagenta": BgLightMagenta, "lightCyan": BgLightCyan, "lightWhite": BgLightWhite, }
ExBgColors extra background colors map
View Source
var ExFgColors = map[string]Color{ "darkGray": FgDarkGray, "lightRed": FgLightRed, "lightGreen": FgLightGreen, "lightYellow": FgLightYellow, "lightBlue": FgLightBlue, "lightMagenta": FgLightMagenta, "lightCyan": FgLightCyan, "lightWhite": FgLightWhite, }
ExFgColors extra foreground colors map
View Source
var FgColors = map[string]Color{ "black": FgBlack, "red": FgRed, "green": FgGreen, "yellow": FgYellow, "blue": FgBlue, "magenta": FgMagenta, "cyan": FgCyan, "white": FgWhite, "default": FgDefault, }
FgColors foreground colors map
View Source
var Options = map[string]Color{ "reset": OpReset, "bold": OpBold, "fuzzy": OpFuzzy, "italic": OpItalic, "underscore": OpUnderscore, "blink": OpBlink, "reverse": OpReverse, "concealed": OpConcealed, }
Options color options map
View Source
var Styles = map[string]Style{ "info": {OpReset, FgGreen}, "note": {OpBold, FgLightCyan}, "light": {FgLightWhite, BgRed}, "error": {OpBold, FgRed}, "danger": {OpBold, FgRed}, "notice": {OpBold, FgCyan}, "success": {OpBold, FgGreen}, "comment": {OpReset, FgMagenta}, "primary": {OpReset, FgBlue}, "warning": {OpBold, FgYellow}, "question": {OpReset, FgMagenta}, "secondary": {FgDarkGray}, }
Styles internal defined styles, like bootstrap styles. Usage:
color.Styles["info"].Println("message")
View Source
var Themes = map[string]*Theme{ "trace": Trace, "debug": Debug, "info": Info, "warn": Warn, "error": Error, "fatal": Fatal, "note": Note, "success": Success, "comment": Comment, "primary": Primary, "question": Question, }
Themes internal defined themes. Usage:
color.Themes["info"].Println("message")
Functions ¶
func RenderCode ¶
RenderCode render message by color code.
Types ¶
type Color ¶
type Color uint8
Color Color16, 16 color value type 3(2^3=8) OR 4(2^4=16) bite color.
const ( FgBlack Color = iota + 30 FgRed FgGreen FgYellow FgBlue FgMagenta // 品红 FgCyan // 青色 FgWhite // FgDefault revert default FG FgDefault Color = 39 )
Foreground colors. basic foreground colors 30 - 37
const ( FgDarkGray Color = iota + 90 // 亮黑(灰) FgLightRed FgLightGreen FgLightYellow FgLightBlue FgLightMagenta FgLightCyan FgLightWhite // FgGray is alias of FgDarkGray FgGray Color = 90 // 亮黑(灰) )
Extra foreground color 90 - 97(非标准)
const ( BgBlack Color = iota + 40 BgRed BgGreen BgYellow // BgBrown like yellow BgBlue BgMagenta BgCyan BgWhite // BgDefault revert default BG BgDefault Color = 49 )
Background colors. basic background colors 40 - 47
const ( BgDarkGray Color = iota + 99 BgLightRed BgLightGreen BgLightYellow BgLightBlue BgLightMagenta BgLightCyan BgLightWhite // BgGray is alias of BgDarkGray BgGray Color = 100 )
Extra background color 100 - 107(非标准)
const ( OpReset Color = iota // 0 重置所有设置 OpBold // 1 加粗 OpFuzzy // 2 模糊(不是所有的终端仿真器都支持) OpItalic // 3 斜体(不是所有的终端仿真器都支持) OpUnderscore // 4 下划线 OpBlink // 5 闪烁 OpFastBlink // 5 快速闪烁(未广泛支持) OpReverse // 7 颠倒的 交换背景色与前景色 OpConcealed // 8 隐匿的 OpStrikethrough // 9 删除的,删除线(未广泛支持) )
Option settings
type Style ¶
type Style []Color
Click to show internal directories.
Click to hide internal directories.