Documentation ¶
Overview ¶
Package color provides printing in ANSI colors.
TODO: Need to document this. See the Color function for now.
This package uses code from github.com/wsxiaoys/terminal(https://github.com/wsxiaoys/terminal). Many thanks.
Index ¶
- Constants
- Variables
- func Color(s string, escape rune) string
- func ColorCode(s string) string
- func Decolor(s string, escape rune) string
- func Uncolor(s string) string
- type Colorizer
- func (c *Colorizer) Color(s string) string
- func (c *Colorizer) Enabled() bool
- func (c *Colorizer) EscapeChar() rune
- func (c *Colorizer) Fprint(w io.Writer, a ...interface{}) (int, error)
- func (c *Colorizer) Fprintf(w io.Writer, format string, a ...interface{}) (int, error)
- func (c *Colorizer) Fprintln(w io.Writer, a ...interface{}) (int, error)
- func (c *Colorizer) Print(a ...interface{}) (int, error)
- func (c *Colorizer) Printf(format string, a ...interface{}) (int, error)
- func (c *Colorizer) Println(a ...interface{}) (int, error)
- func (c *Colorizer) Set(s string) (err error)
- func (c *Colorizer) SetEnabled(b bool)
- func (c *Colorizer) SetEscapeChar(r rune)
- func (c *Colorizer) SetFile(f *os.File)
- func (c *Colorizer) SetOutput(w io.Writer)
- func (c *Colorizer) Sprint(a ...interface{}) string
- func (c *Colorizer) Sprintf(format string, a ...interface{}) string
- func (c *Colorizer) Sprintln(a ...interface{}) string
- func (c Colorizer) String() string
- func (c Colorizer) Type() string
Constants ¶
const ColorReset = "\033[0m"
ColorReset is the string that resets the text to default style.
Variables ¶
var ErrInvalidEscape = errors.New("invalid escape rune")
ErrInvalidEscape is an error that is used when the parser panics.
var ErrUnexpectedEOF = errors.New("unexpected EOF while parsing")
Functions ¶
func Color ¶
Color translates a string into an escaped string.
This example will output the text with a Blue foreground and a Black background
color.Println("@{bK}Example Text")
This one will output the text with a red foreground
color.Println("@rExample Text")
This one will escape the @
color.Println("@@")
Full color syntax code
@{rgbcmykwRGBCMYKW} foreground/background color r/R: Red g/G: Green b/B: Blue c/C: Cyan m/M: Magenta y/Y: Yellow k/K: Black w/W: White @{|} Reset format style @{!./_} Bold / Dim / Italic / Underline @{^&} Blink / Fast blink @{?} Reverse the foreground and background color @{-} Hide the text
Note some of the functions are not widely supported, like "Fast blink" and "Italic".
Types ¶
type Colorizer ¶
type Colorizer struct {
// contains filtered or unexported fields
}
func (*Colorizer) EscapeChar ¶
func (*Colorizer) Set ¶
Set sets c on or off, with s one of "auto", "always", or "never", otherwise an error is returned.
Note: if "auto" is passed, and SetOutput was passed an io.Writer that is not an *os.File, nothing will happen. This lets you decide whether you want it to fall back to enabled or disabled.
func (*Colorizer) SetEnabled ¶
func (*Colorizer) SetEscapeChar ¶
SetEscapeChar sets the escape character, which can be one of the following characters:
@ * + = ~
If it is none of these characters, then this function panics with ErrInvalidEscape.