Documentation ¶
Overview ¶
Package aurora implements ANSI-colors
Example (Printf) ¶
fmt.Printf("%d %s", Blue(100), BgBlue("cats"))
Output: �[34m100�[0m �[44mcats�[0m
Index ¶
- func Sprintf(format interface{}, args ...interface{}) string
- type Aurora
- type Color
- type Value
- func BgBlack(arg interface{}) Value
- func BgBlue(arg interface{}) Value
- func BgBrightBlack(arg interface{}) Value
- func BgBrightBlue(arg interface{}) Value
- func BgBrightCyan(arg interface{}) Value
- func BgBrightGreen(arg interface{}) Value
- func BgBrightMagenta(arg interface{}) Value
- func BgBrightRed(arg interface{}) Value
- func BgBrightWhite(arg interface{}) Value
- func BgBrightYellow(arg interface{}) Value
- func BgBrown(arg interface{}) Valuedeprecated
- func BgCyan(arg interface{}) Value
- func BgGray(n uint8, arg interface{}) Value
- func BgGreen(arg interface{}) Value
- func BgIndex(n uint8, arg interface{}) Value
- func BgMagenta(arg interface{}) Value
- func BgRed(arg interface{}) Value
- func BgWhite(arg interface{}) Value
- func BgYellow(arg interface{}) Value
- func Black(arg interface{}) Value
- func Blink(arg interface{}) Value
- func Blue(arg interface{}) Value
- func Bold(arg interface{}) Value
- func BrightBlack(arg interface{}) Value
- func BrightBlue(arg interface{}) Value
- func BrightCyan(arg interface{}) Value
- func BrightGreen(arg interface{}) Value
- func BrightMagenta(arg interface{}) Value
- func BrightRed(arg interface{}) Value
- func BrightWhite(arg interface{}) Value
- func BrightYellow(arg interface{}) Value
- func Brown(arg interface{}) Valuedeprecated
- func Colorize(arg interface{}, color Color) Value
- func Conceal(arg interface{}) Value
- func CrossedOut(arg interface{}) Value
- func Cyan(arg interface{}) Value
- func DoublyUnderline(arg interface{}) Value
- func Encircled(arg interface{}) Value
- func Faint(arg interface{}) Value
- func Fraktur(arg interface{}) Value
- func Framed(arg interface{}) Value
- func Gray(n uint8, arg interface{}) Value
- func Green(arg interface{}) Value
- func Hidden(arg interface{}) Value
- func Index(n uint8, arg interface{}) Value
- func Inverse(arg interface{}) Value
- func Italic(arg interface{}) Value
- func Magenta(arg interface{}) Value
- func Overlined(arg interface{}) Value
- func RapidBlink(arg interface{}) Value
- func Red(arg interface{}) Value
- func Reset(arg interface{}) Value
- func Reverse(arg interface{}) Value
- func SlowBlink(arg interface{}) Value
- func StrikeThrough(arg interface{}) Value
- func Underline(arg interface{}) Value
- func White(arg interface{}) Value
- func Yellow(arg interface{}) Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sprintf ¶
func Sprintf(format interface{}, args ...interface{}) string
Sprintf allows to use Value as format. For example
v := Sprintf(Red("total: +3.5f points"), Blue(3.14))
In this case "total:" and "points" will be red, but 3.14 will be blue. But, in another example
v := Sprintf(Red("total: +3.5f points"), 3.14)
full string will be red. And no way to clear 3.14 to default format and color
Example ¶
fmt.Print( Sprintf( Blue("we've got %d cats, but want %d"), // <- blue format Cyan(5), Bold(Magenta(25)), ), )
Output: �[34mwe've got �[0;36m5�[0;34m cats, but want �[0;1;35m25�[0;34m�[0m
Types ¶
type Aurora ¶
type Aurora interface { // Reset wraps given argument returning Value // without formats and colors. Reset(arg interface{}) Value // // Formats // // // Bold or increased intensity (1). Bold(arg interface{}) Value // Faint, decreased intensity (2). Faint(arg interface{}) Value // // DoublyUnderline or Bold off, double-underline // per ECMA-48 (21). DoublyUnderline(arg interface{}) Value // Fraktur, rarely supported (20). Fraktur(arg interface{}) Value // // Italic, not widely supported, sometimes // treated as inverse (3). Italic(arg interface{}) Value // Underline (4). Underline(arg interface{}) Value // // SlowBlink, blinking less than 150 // per minute (5). SlowBlink(arg interface{}) Value // RapidBlink, blinking 150+ per minute, // not widely supported (6). RapidBlink(arg interface{}) Value // Blink is alias for the SlowBlink. Blink(arg interface{}) Value // // Reverse video, swap foreground and // background colors (7). Reverse(arg interface{}) Value // Inverse is alias for the Reverse Inverse(arg interface{}) Value // // Conceal, hidden, not widely supported (8). Conceal(arg interface{}) Value // Hidden is alias for the Conceal Hidden(arg interface{}) Value // // CrossedOut, characters legible, but // marked for deletion (9). CrossedOut(arg interface{}) Value // StrikeThrough is alias for the CrossedOut. StrikeThrough(arg interface{}) Value // // Framed (51). Framed(arg interface{}) Value // Encircled (52). Encircled(arg interface{}) Value // // Overlined (53). Overlined(arg interface{}) Value // // Foreground colors // // // Black foreground color (30) Black(arg interface{}) Value // Red foreground color (31) Red(arg interface{}) Value // Green foreground color (32) Green(arg interface{}) Value // Yellow foreground color (33) Yellow(arg interface{}) Value // Brown foreground color (33) // // Deprecated: use Yellow instead, following specification Brown(arg interface{}) Value // Blue foreground color (34) Blue(arg interface{}) Value // Magenta foreground color (35) Magenta(arg interface{}) Value // Cyan foreground color (36) Cyan(arg interface{}) Value // White foreground color (37) White(arg interface{}) Value // // Bright foreground colors // // BrightBlack foreground color (90) BrightBlack(arg interface{}) Value // BrightRed foreground color (91) BrightRed(arg interface{}) Value // BrightGreen foreground color (92) BrightGreen(arg interface{}) Value // BrightYellow foreground color (93) BrightYellow(arg interface{}) Value // BrightBlue foreground color (94) BrightBlue(arg interface{}) Value // BrightMagenta foreground color (95) BrightMagenta(arg interface{}) Value // BrightCyan foreground color (96) BrightCyan(arg interface{}) Value // BrightWhite foreground color (97) BrightWhite(arg interface{}) Value // // Other // // Index of pre-defined 8-bit foreground color // from 0 to 255 (38;5;n). // // 0- 7: standard colors (as in ESC [ 30–37 m) // 8- 15: high intensity colors (as in ESC [ 90–97 m) // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) // 232-255: grayscale from black to white in 24 steps // Index(n uint8, arg interface{}) Value // Gray from 0 to 23. Gray(n uint8, arg interface{}) Value // // Background colors // // // BgBlack background color (40) BgBlack(arg interface{}) Value // BgRed background color (41) BgRed(arg interface{}) Value // BgGreen background color (42) BgGreen(arg interface{}) Value // BgYellow background color (43) BgYellow(arg interface{}) Value // BgBrown background color (43) // // Deprecated: use BgYellow instead, following specification BgBrown(arg interface{}) Value // BgBlue background color (44) BgBlue(arg interface{}) Value // BgMagenta background color (45) BgMagenta(arg interface{}) Value // BgCyan background color (46) BgCyan(arg interface{}) Value // BgWhite background color (47) BgWhite(arg interface{}) Value // // Bright background colors // // BgBrightBlack background color (100) BgBrightBlack(arg interface{}) Value // BgBrightRed background color (101) BgBrightRed(arg interface{}) Value // BgBrightGreen background color (102) BgBrightGreen(arg interface{}) Value // BgBrightYellow background color (103) BgBrightYellow(arg interface{}) Value // BgBrightBlue background color (104) BgBrightBlue(arg interface{}) Value // BgBrightMagenta background color (105) BgBrightMagenta(arg interface{}) Value // BgBrightCyan background color (106) BgBrightCyan(arg interface{}) Value // BgBrightWhite background color (107) BgBrightWhite(arg interface{}) Value // // Other // // BgIndex of 8-bit pre-defined background color // from 0 to 255 (48;5;n). // // 0- 7: standard colors (as in ESC [ 40–47 m) // 8- 15: high intensity colors (as in ESC [100–107 m) // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) // 232-255: grayscale from black to white in 24 steps // BgIndex(n uint8, arg interface{}) Value // BgGray from 0 to 23. BgGray(n uint8, arg interface{}) Value // // Special // // Colorize removes existing colors and // formats of the argument and applies given. Colorize(arg interface{}, color Color) Value // // Support methods // // Sprintf allows to use colored format. Sprintf(format interface{}, args ...interface{}) string }
An Aurora implements colorizer interface. It also can be a non-colorizer
func NewAurora ¶
NewAurora returns a new Aurora interface that will support or not support colors depending the enableColors argument
Example (Colors) ¶
a := NewAurora(true) fmt.Println(a.Red("Red"))
Output: �[31mRed�[0m
Example (No_colors) ¶
a := NewAurora(false) fmt.Println(a.Red("Not red"))
Output: Not red
type Color ¶
type Color uint
A Color type is a color. It can contain one background color, one foreground color and a format, including ideogram related formats.
const ( BoldFm Color = 1 << iota // 1 FaintFm // 2 ItalicFm // 3 UnderlineFm // 4 SlowBlinkFm // 5 RapidBlinkFm // 6 ReverseFm // 7 ConcealFm // 8 CrossedOutFm // 9 FrakturFm // 20 DoublyUnderlineFm // 21 or bold off for some systems FramedFm // 51 EncircledFm // 52 OverlinedFm // 53 InverseFm = ReverseFm // alias to ReverseFm BlinkFm = SlowBlinkFm // alias to SlowBlinkFm HiddenFm = ConcealFm // alias to ConcealFm StrikeThroughFm = CrossedOutFm // alias to CrossedOutFm )
Special formats
const ( BlackFg Color = (iota << shiftFg) | flagFg // 30, 90 RedFg // 31, 91 GreenFg // 32, 92 YellowFg // 33, 93 BlueFg // 34, 94 MagentaFg // 35, 95 CyanFg // 36, 96 WhiteFg // 37, 97 BrightFg Color = ((1 << 3) << shiftFg) | flagFg // -> 90 // BrownFg represents brown foreground color. // // Deprecated: use YellowFg instead, following specifications BrownFg = YellowFg )
Foreground colors and related formats
const ( BlackBg Color = (iota << shiftBg) | flagBg // 40, 100 RedBg // 41, 101 GreenBg // 42, 102 YellowBg // 43, 103 BlueBg // 44, 104 MagentaBg // 45, 105 CyanBg // 46, 106 WhiteBg // 47, 107 BrightBg Color = ((1 << 3) << shiftBg) | flagBg // -> 100 // BrownBg represents brown foreground color. // // Deprecated: use YellowBg instead, following specifications BrownBg = YellowBg )
Background colors and related formats
type Value ¶
type Value interface { // String returns string with colors. If there are any color // or format the string will be terminated with \033[0m fmt.Stringer // Format implements fmt.Formatter interface fmt.Formatter // Color returns value's color Color() Color // Value returns value's value (welcome to the tautology club) Value() interface{} // Bleach returns copy of original value without colors // // Deprecated: use Reset instead. Bleach() Value // Reset colors and formats Reset() Value // // Formats // // // Bold or increased intensity (1). Bold() Value // Faint, decreased intensity, reset the Bold (2). Faint() Value // // DoublyUnderline or Bold off, double-underline // per ECMA-48 (21). It depends. DoublyUnderline() Value // Fraktur, rarely supported (20). Fraktur() Value // // Italic, not widely supported, sometimes // treated as inverse (3). Italic() Value // Underline (4). Underline() Value // // SlowBlink, blinking less than 150 // per minute (5). SlowBlink() Value // RapidBlink, blinking 150+ per minute, // not widely supported (6). RapidBlink() Value // Blink is alias for the SlowBlink. Blink() Value // // Reverse video, swap foreground and // background colors (7). Reverse() Value // Inverse is alias for the Reverse Inverse() Value // // Conceal, hidden, not widely supported (8). Conceal() Value // Hidden is alias for the Conceal Hidden() Value // // CrossedOut, characters legible, but // marked for deletion (9). CrossedOut() Value // StrikeThrough is alias for the CrossedOut. StrikeThrough() Value // // Framed (51). Framed() Value // Encircled (52). Encircled() Value // // Overlined (53). Overlined() Value // // Foreground colors // // // Black foreground color (30) Black() Value // Red foreground color (31) Red() Value // Green foreground color (32) Green() Value // Yellow foreground color (33) Yellow() Value // Brown foreground color (33) // // Deprecated: use Yellow instead, following specification Brown() Value // Blue foreground color (34) Blue() Value // Magenta foreground color (35) Magenta() Value // Cyan foreground color (36) Cyan() Value // White foreground color (37) White() Value // // Bright foreground colors // // BrightBlack foreground color (90) BrightBlack() Value // BrightRed foreground color (91) BrightRed() Value // BrightGreen foreground color (92) BrightGreen() Value // BrightYellow foreground color (93) BrightYellow() Value // BrightBlue foreground color (94) BrightBlue() Value // BrightMagenta foreground color (95) BrightMagenta() Value // BrightCyan foreground color (96) BrightCyan() Value // BrightWhite foreground color (97) BrightWhite() Value // // Other // // Index of pre-defined 8-bit foreground color // from 0 to 255 (38;5;n). // // 0- 7: standard colors (as in ESC [ 30–37 m) // 8- 15: high intensity colors (as in ESC [ 90–97 m) // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) // 232-255: grayscale from black to white in 24 steps // Index(n uint8) Value // Gray from 0 to 24. Gray(n uint8) Value // // Background colors // // // BgBlack background color (40) BgBlack() Value // BgRed background color (41) BgRed() Value // BgGreen background color (42) BgGreen() Value // BgYellow background color (43) BgYellow() Value // BgBrown background color (43) // // Deprecated: use BgYellow instead, following specification BgBrown() Value // BgBlue background color (44) BgBlue() Value // BgMagenta background color (45) BgMagenta() Value // BgCyan background color (46) BgCyan() Value // BgWhite background color (47) BgWhite() Value // // Bright background colors // // BgBrightBlack background color (100) BgBrightBlack() Value // BgBrightRed background color (101) BgBrightRed() Value // BgBrightGreen background color (102) BgBrightGreen() Value // BgBrightYellow background color (103) BgBrightYellow() Value // BgBrightBlue background color (104) BgBrightBlue() Value // BgBrightMagenta background color (105) BgBrightMagenta() Value // BgBrightCyan background color (106) BgBrightCyan() Value // BgBrightWhite background color (107) BgBrightWhite() Value // // Other // // BgIndex of 8-bit pre-defined background color // from 0 to 255 (48;5;n). // // 0- 7: standard colors (as in ESC [ 40–47 m) // 8- 15: high intensity colors (as in ESC [100–107 m) // 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) // 232-255: grayscale from black to white in 24 steps // BgIndex(n uint8) Value // BgGray from 0 to 24. BgGray(n uint8) Value // // Special // // Colorize removes existing colors and // formats of the argument and applies given. Colorize(color Color) Value // contains filtered or unexported methods }
A Value represents any printable value with it's color
func BgBrightMagenta ¶
func BgBrightMagenta(arg interface{}) Value
BgBrightMagenta background color (105)
func BgBrightYellow ¶
func BgBrightYellow(arg interface{}) Value
BgBrightYellow background color (103)
func BgIndex ¶
BgIndex of 8-bit pre-defined background color from 0 to 255 (48;5;n).
0- 7: standard colors (as in ESC [ 40–47 m) 8- 15: high intensity colors (as in ESC [100–107 m) 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) 232-255: grayscale from black to white in 24 steps
func Bold ¶
func Bold(arg interface{}) Value
Bold or increased intensity (1).
Example ¶
fmt.Println("value:", Bold(Green(99)))
Output: value: �[1;32m99�[0m
func Colorize ¶
Colorize wraps given value into Value with given colors. For example
s := Colorize("some", BlueFg|GreenBg|BoldFm)
returns a Value with blue foreground, green background and bold. Unlike functions like Red/BgBlue/Bold etc. This function clears all previous colors and formats. Thus
s := Colorize(Red("some"), BgBlue)
clears red color from value
func Conceal ¶
func Conceal(arg interface{}) Value
Conceal hides text, preserving an ability to select the text and copy it. It is not widely supported (8).
func CrossedOut ¶
func CrossedOut(arg interface{}) Value
CrossedOut makes characters legible, but marked for deletion (9).
func DoublyUnderline ¶
func DoublyUnderline(arg interface{}) Value
DoublyUnderline or Bold off, double-underline per ECMA-48 (21).
func Faint ¶
func Faint(arg interface{}) Value
Faint decreases intensity (2). The Faint rejects the Bold.
func Index ¶
Index of pre-defined 8-bit foreground color from 0 to 255 (38;5;n).
0- 7: standard colors (as in ESC [ 30–37 m) 8- 15: high intensity colors (as in ESC [ 90–97 m) 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) 232-255: grayscale from black to white in 24 steps
func Italic ¶
func Italic(arg interface{}) Value
Italic is not widely supported, sometimes treated as inverse (3).
func RapidBlink ¶
func RapidBlink(arg interface{}) Value
RapidBlink makes text blink 150+ per minute. It is not widely supported (6).
func Red ¶
func Red(arg interface{}) Value
Red foreground color (31)
Example ¶
fmt.Println("value exceeds min-threshold:", Red(3.14))
Output: value exceeds min-threshold: �[31m3.14�[0m
func Reset ¶
func Reset(arg interface{}) Value
Reset wraps given argument returning Value without formats and colors.
func Reverse ¶
func Reverse(arg interface{}) Value
Reverse video, swap foreground and background colors (7).
func SlowBlink ¶
func SlowBlink(arg interface{}) Value
SlowBlink makes text blink less than 150 per minute (5).
func StrikeThrough ¶
func StrikeThrough(arg interface{}) Value
StrikeThrough is alias for the CrossedOut.