aurora: github.com/logrusorgru/aurora Index | Examples | Files

package aurora

import "github.com/logrusorgru/aurora"

Package aurora implements ANSI-colors

Code:

fmt.Printf("%d %s", Blue(100), BgBlue("cats"))

Output:

100 cats

Index

Examples

Package Files

aurora.go color.go sprintf.go value.go wrap.go

func Sprintf Uses

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

Code:

fmt.Print(
    Sprintf(
        Blue("we've got %d cats, but want %d"), // <- blue format
        Cyan(5),
        Bold(Magenta(25)),
    ),
)

Output:

we've got 5 cats, but want 25

type Aurora Uses

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 Uses

func NewAurora(enableColors bool) Aurora

NewAurora returns a new Aurora interface that will support or not support colors depending the enableColors argument

Code:

a := NewAurora(true)
fmt.Println(a.Red("Red"))

Output:

Red

type Color Uses

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

func (Color) IsValid Uses

func (c Color) IsValid() bool

IsValid returns true always

Deprecated: don't use this method anymore

func (Color) Nos Uses

func (c Color) Nos(zero bool) string

Nos returns string like 1;7;31;45. It may be an empty string for empty color. If the zero is true, then the string is prepended with 0;

type Value Uses

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 BgBlack Uses

func BgBlack(arg interface{}) Value

BgBlack background color (40)

func BgBlue Uses

func BgBlue(arg interface{}) Value

BgBlue background color (44)

func BgBrightBlack Uses

func BgBrightBlack(arg interface{}) Value

BgBrightBlack background color (100)

func BgBrightBlue Uses

func BgBrightBlue(arg interface{}) Value

BgBrightBlue background color (104)

func BgBrightCyan Uses

func BgBrightCyan(arg interface{}) Value

BgBrightCyan background color (106)

func BgBrightGreen Uses

func BgBrightGreen(arg interface{}) Value

BgBrightGreen background color (102)

func BgBrightMagenta Uses

func BgBrightMagenta(arg interface{}) Value

BgBrightMagenta background color (105)

func BgBrightRed Uses

func BgBrightRed(arg interface{}) Value

BgBrightRed background color (101)

func BgBrightWhite Uses

func BgBrightWhite(arg interface{}) Value

BgBrightWhite background color (107)

func BgBrightYellow Uses

func BgBrightYellow(arg interface{}) Value

BgBrightYellow background color (103)

func BgBrown Uses

func BgBrown(arg interface{}) Value

BgBrown background color (43)

Deprecated: use BgYellow instead, following specification

func BgCyan Uses

func BgCyan(arg interface{}) Value

BgCyan background color (46)

func BgGray Uses

func BgGray(n uint8, arg interface{}) Value

BgGray from 0 to 24.

func BgGreen Uses

func BgGreen(arg interface{}) Value

BgGreen background color (42)

func BgIndex Uses

func BgIndex(n uint8, arg interface{}) Value

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 BgMagenta Uses

func BgMagenta(arg interface{}) Value

BgMagenta background color (45)

func BgRed Uses

func BgRed(arg interface{}) Value

BgRed background color (41)

func BgWhite Uses

func BgWhite(arg interface{}) Value

BgWhite background color (47)

func BgYellow Uses

func BgYellow(arg interface{}) Value

BgYellow background color (43)

func Black Uses

func Black(arg interface{}) Value

Black foreground color (30)

func Blink(arg interface{}) Value

Blink is alias for the SlowBlink.

func Blue Uses

func Blue(arg interface{}) Value

Blue foreground color (34)

func Bold Uses

func Bold(arg interface{}) Value

Bold or increased intensity (1).

Code:

fmt.Println("value:", Bold(Green(99)))

Output:

value: 99

func BrightBlack Uses

func BrightBlack(arg interface{}) Value

BrightBlack foreground color (90)

func BrightBlue Uses

func BrightBlue(arg interface{}) Value

BrightBlue foreground color (94)

func BrightCyan Uses

func BrightCyan(arg interface{}) Value

BrightCyan foreground color (96)

func BrightGreen Uses

func BrightGreen(arg interface{}) Value

BrightGreen foreground color (92)

func BrightMagenta Uses

func BrightMagenta(arg interface{}) Value

BrightMagenta foreground color (95)

func BrightRed Uses

func BrightRed(arg interface{}) Value

BrightRed foreground color (91)

func BrightWhite Uses

func BrightWhite(arg interface{}) Value

BrightWhite foreground color (97)

func BrightYellow Uses

func BrightYellow(arg interface{}) Value

BrightYellow foreground color (93)

func Brown Uses

func Brown(arg interface{}) Value

Brown foreground color (33)

Deprecated: use Yellow instead, following specification

func Colorize Uses

func Colorize(arg interface{}, color Color) Value

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 Uses

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 Uses

func CrossedOut(arg interface{}) Value

CrossedOut makes characters legible, but marked for deletion (9).

func Cyan Uses

func Cyan(arg interface{}) Value

Cyan foreground color (36)

func DoublyUnderline Uses

func DoublyUnderline(arg interface{}) Value

DoublyUnderline or Bold off, double-underline per ECMA-48 (21).

func Encircled Uses

func Encircled(arg interface{}) Value

Encircled (52).

func Faint Uses

func Faint(arg interface{}) Value

Faint decreases intensity (2). The Faint rejects the Bold.

func Fraktur Uses

func Fraktur(arg interface{}) Value

Fraktur is rarely supported (20).

func Framed Uses

func Framed(arg interface{}) Value

Framed (51).

func Gray Uses

func Gray(n uint8, arg interface{}) Value

Gray from 0 to 24.

func Green Uses

func Green(arg interface{}) Value

Green foreground color (32)

func Hidden Uses

func Hidden(arg interface{}) Value

Hidden is alias for the Conceal

func Index Uses

func Index(n uint8, arg interface{}) Value

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 Inverse Uses

func Inverse(arg interface{}) Value

Inverse is alias for the Reverse

func Italic Uses

func Italic(arg interface{}) Value

Italic is not widely supported, sometimes treated as inverse (3).

func Magenta Uses

func Magenta(arg interface{}) Value

Magenta foreground color (35)

func Overlined Uses

func Overlined(arg interface{}) Value

Overlined (53).

func RapidBlink(arg interface{}) Value

RapidBlink makes text blink 150+ per minute. It is not widely supported (6).

func Red Uses

func Red(arg interface{}) Value

Red foreground color (31)

Code:

fmt.Println("value exceeds min-threshold:", Red(3.14))

Output:

value exceeds min-threshold: 3.14

func Reset Uses

func Reset(arg interface{}) Value

Reset wraps given argument returning Value without formats and colors.

func Reverse Uses

func Reverse(arg interface{}) Value

Reverse video, swap foreground and background colors (7).

func SlowBlink(arg interface{}) Value

SlowBlink makes text blink less than 150 per minute (5).

func StrikeThrough Uses

func StrikeThrough(arg interface{}) Value

StrikeThrough is alias for the CrossedOut.

func Underline Uses

func Underline(arg interface{}) Value

Underline (4).

func White Uses

func White(arg interface{}) Value

White foreground color (37)

func Yellow Uses

func Yellow(arg interface{}) Value

Yellow foreground color (33)

Package aurora imports 3 packages (graph) and is imported by 174 packages. Updated 2019-11-16. Refresh now. Tools for package owners.