Documentation ¶
Index ¶
- Variables
- func Disable() func()
- func Enable() func()
- func Enabled() bool
- func EscapeString(attr Attribute) string
- func EscapeWriter(w io.Writer, attr Attribute) (n int, err error)
- func ResetString() string
- func ResetWriter(w io.Writer) (n int, err error)
- func StyleString(s string) string
- type Attribute
- type SimpleAttribute
- type Style
- func (s *Style) Add(attrs ...Attribute) *Style
- func (s *Style) Copy() *Style
- func (s *Style) Fprint(w io.Writer, args ...interface{}) (n int, err error)
- func (s *Style) Fprintf(w io.Writer, format string, args ...interface{}) (n int, err error)
- func (s *Style) Fprintln(w io.Writer, args ...interface{}) (n int, err error)
- func (s *Style) NewWith(attrs ...Attribute) *Style
- func (s *Style) Print(args ...interface{}) (n int, err error)
- func (s *Style) Printf(format string, args ...interface{}) (n int, err error)
- func (s *Style) Println(args ...interface{}) (n int, err error)
- func (s *Style) Sprint(args ...interface{}) string
- func (s *Style) Sprintf(format string, args ...interface{}) string
- func (s *Style) Sprintln(args ...interface{}) string
Constants ¶
This section is empty.
Variables ¶
var ( // AttributeMap contains a mapping between names and attributes. This is // used by StyleString to search an replace attribute names with their ANSI // color escape sequences. It is exported so that users can add more // mappings if desired. AttributeMap = map[string]Attribute{ "reset": Reset, "bold": Bold, "faint": Faint, "italic": Italic, "underline": Underline, "blinkslow": BlinkSlow, "blinkrapid": BlinkRapid, "reversevideo": ReverseVideo, "concealed": Concealed, "crossedout": CrossedOut, "fraktur": Fraktur, "doubleunderline": DoubleUnderline, "normal": Normal, "nofraktur": NoFraktur, "nounderline": NoUnderline, "noblink": NoBlink, "proportionalspacing": ProportionalSpacing, "noreverse": NoReverse, "reveal": Reveal, "nocrossedout": NoCrossedOut, "fgblack": FgBlack, "fgred": FgRed, "fggreen": FgGreen, "fgyellow": FgYellow, "fgblue": FgBlue, "fgmagenta": FgMagenta, "fgcyan": FgCyan, "fgwhite": FgWhite, "fgcolor": FgColor, "fgdefault": FgDefault, "bgblack": BgBlack, "bgred": BgRed, "bggreen": BgGreen, "bgyellow": BgYellow, "bgblue": BgBlue, "bgmagenta": BgMagenta, "bgcyan": BgCyan, "bgwhite": BgWhite, "bgcolor": BgColor, "bgdefault": BgDefault, "fghiblack": FgHiBlack, "fghired": FgHiRed, "fghigreen": FgHiGreen, "fghiyellow": FgHiYellow, "fghiblue": FgHiBlue, "fghimagenta": FgHiMagenta, "fghicyan": FgHiCyan, "fghiwhite": FgHiWhite, "bghiblack": BgHiBlack, "bghired": BgHiRed, "bghigreen": BgHiGreen, "bghiyellow": BgHiYellow, "bghiblue": BgHiBlue, "bghimagenta": BgHiMagenta, "bghicyan": BgHiCyan, "bghiwhite": BgHiWhite, "black": FgBlack, "red": FgRed, "green": FgGreen, "yellow": FgYellow, "blue": FgBlue, "magenta": FgMagenta, "cyan": FgCyan, "white": FgWhite, "default": FgDefault, "rst": Reset, "blink": BlinkSlow, "strike": CrossedOut, "strikethrough": CrossedOut, } )
var ( // Stdout is an io.Writer for stdout which properly handles escape // sequences. Stdout = colorable.NewColorableStdout() )
Functions ¶
func Disable ¶
func Disable() func()
Disable disables output coloring. The returned func can be used in combination with defer to restore the previous state.
func Enable ¶
func Enable() func()
Enable enables output coloring. The returned func can be used in combination with defer to restore the previous state.
func EscapeString ¶
EscapeString creates the escape sequence for given attribute and returns it. If coloring is disabled this returns an empty string.
func EscapeWriter ¶
EscapeWriter creates the escape sequence for given attribute and writes to w. It returns the number of bytes written and any write error encountered. If coloring is disabled this is a no-op.
func ResetString ¶
func ResetString() string
ResetString creates the escape sequence for resetting all style attributes and returns it. If coloring is disabled this returns an empty string.
func ResetWriter ¶
ResetWriter creates the escape sequence for resetting all style attributes and writes to w. It returns the number of bytes written and any write error encountered. If coloring is disabled this is a no-op.
func StyleString ¶
StyleString replaces all supported style attributes of the from "{attr1,attr2}" in s with the corresponding ANSI escape sequences. If an attribute is not recognized it is not replaced. If styles are disabled, style attributes are replaced with empty strings. This supports all attribute names defined in AttributeMap.
Types ¶
type Attribute ¶
type Attribute interface {
// contains filtered or unexported methods
}
Attribute is an attribute of an ANSI escape sequence.
type SimpleAttribute ¶
type SimpleAttribute uint8
SimpleAttribute is an attribute that is just one uint8 value.
const ( Reset SimpleAttribute = iota Bold Faint Italic Underline BlinkSlow BlinkRapid ReverseVideo Concealed CrossedOut )
Base style attributes
const ( DefaultFont SimpleAttribute = iota + 10 AltFont1 AltFont2 AltFont3 AltFont4 AltFont5 AltFont6 AltFont7 AltFont8 AltFont9 )
Font attributes
const ( Fraktur SimpleAttribute = iota + 20 DoubleUnderline Normal NoFraktur NoUnderline NoBlink ProportionalSpacing NoReverse Reveal NoCrossedOut )
Style reset attributes
const ( FgBlack SimpleAttribute = iota + 30 FgRed FgGreen FgYellow FgBlue FgMagenta FgCyan FgWhite FgColor FgDefault )
Foreground text colors
const ( BgBlack SimpleAttribute = iota + 40 BgRed BgGreen BgYellow BgBlue BgMagenta BgCyan BgWhite BgColor BgDefault )
Background text colors
const ( FgHiBlack SimpleAttribute = iota + 90 FgHiRed FgHiGreen FgHiYellow FgHiBlue FgHiMagenta FgHiCyan FgHiWhite )
Foreground Hi-Intensity text colors
const ( BgHiBlack SimpleAttribute = iota + 100 BgHiRed BgHiGreen BgHiYellow BgHiBlue BgHiMagenta BgHiCyan BgHiWhite )
Background Hi-Intensity text colors
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style can style and color text.
func (*Style) Fprint ¶
Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Style) Fprintf ¶
Fprintf formats according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
func (*Style) Fprintln ¶
Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Style) NewWith ¶
NewWith creates a new *Style from s with additional attributes. Style s is not altered.
func (*Style) Print ¶
Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Style) Printf ¶
Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.
func (*Style) Println ¶
Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Style) Sprint ¶
Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.