xaurora

package module
v0.0.0-...-89edfd8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package aurora implements ANSI-colors

Index

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

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

func NewAurora(enableColors bool) Aurora

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

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

func (Color) IsValid deprecated

func (c Color) IsValid() bool

IsValid returns true always

Deprecated: don't use this method anymore

func (Color) Nos

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

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

func BgBlack(arg interface{}) Value

BgBlack background color (40)

func BgBlue

func BgBlue(arg interface{}) Value

BgBlue background color (44)

func BgBrightBlack

func BgBrightBlack(arg interface{}) Value

BgBrightBlack background color (100)

func BgBrightBlue

func BgBrightBlue(arg interface{}) Value

BgBrightBlue background color (104)

func BgBrightCyan

func BgBrightCyan(arg interface{}) Value

BgBrightCyan background color (106)

func BgBrightGreen

func BgBrightGreen(arg interface{}) Value

BgBrightGreen background color (102)

func BgBrightMagenta

func BgBrightMagenta(arg interface{}) Value

BgBrightMagenta background color (105)

func BgBrightRed

func BgBrightRed(arg interface{}) Value

BgBrightRed background color (101)

func BgBrightWhite

func BgBrightWhite(arg interface{}) Value

BgBrightWhite background color (107)

func BgBrightYellow

func BgBrightYellow(arg interface{}) Value

BgBrightYellow background color (103)

func BgBrown deprecated

func BgBrown(arg interface{}) Value

BgBrown background color (43)

Deprecated: use BgYellow instead, following specification

func BgCyan

func BgCyan(arg interface{}) Value

BgCyan background color (46)

func BgGray

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

BgGray from 0 to 24.

func BgGreen

func BgGreen(arg interface{}) Value

BgGreen background color (42)

func BgIndex

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

func BgMagenta(arg interface{}) Value

BgMagenta background color (45)

func BgRed

func BgRed(arg interface{}) Value

BgRed background color (41)

func BgWhite

func BgWhite(arg interface{}) Value

BgWhite background color (47)

func BgYellow

func BgYellow(arg interface{}) Value

BgYellow background color (43)

func Black

func Black(arg interface{}) Value

Black foreground color (30)

func Blink(arg interface{}) Value

Blink is alias for the SlowBlink.

func Blue

func Blue(arg interface{}) Value

Blue foreground color (34)

func Bold

func Bold(arg interface{}) Value

Bold or increased intensity (1).

func BrightBlack

func BrightBlack(arg interface{}) Value

BrightBlack foreground color (90)

func BrightBlue

func BrightBlue(arg interface{}) Value

BrightBlue foreground color (94)

func BrightCyan

func BrightCyan(arg interface{}) Value

BrightCyan foreground color (96)

func BrightGreen

func BrightGreen(arg interface{}) Value

BrightGreen foreground color (92)

func BrightMagenta

func BrightMagenta(arg interface{}) Value

BrightMagenta foreground color (95)

func BrightRed

func BrightRed(arg interface{}) Value

BrightRed foreground color (91)

func BrightWhite

func BrightWhite(arg interface{}) Value

BrightWhite foreground color (97)

func BrightYellow

func BrightYellow(arg interface{}) Value

BrightYellow foreground color (93)

func Brown deprecated

func Brown(arg interface{}) Value

Brown foreground color (33)

Deprecated: use Yellow instead, following specification

func Colorize

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

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 Cyan

func Cyan(arg interface{}) Value

Cyan foreground color (36)

func DoublyUnderline

func DoublyUnderline(arg interface{}) Value

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

func Encircled

func Encircled(arg interface{}) Value

Encircled (52).

func Faint

func Faint(arg interface{}) Value

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

func Fraktur

func Fraktur(arg interface{}) Value

Fraktur is rarely supported (20).

func Framed

func Framed(arg interface{}) Value

Framed (51).

func Gray

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

Gray from 0 to 24.

func Green

func Green(arg interface{}) Value

Green foreground color (32)

func Hidden

func Hidden(arg interface{}) Value

Hidden is alias for the Conceal

func Index

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

func Inverse(arg interface{}) Value

Inverse is alias for the Reverse

func Italic

func Italic(arg interface{}) Value

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

func Magenta

func Magenta(arg interface{}) Value

Magenta foreground color (35)

func Overlined

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

func Red(arg interface{}) Value

Red foreground color (31)

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(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.

func Underline

func Underline(arg interface{}) Value

Underline (4).

func White

func White(arg interface{}) Value

White foreground color (37)

func Yellow

func Yellow(arg interface{}) Value

Yellow foreground color (33)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL