Documentation ¶
Overview ¶
Package color is a modification of https://github.com/fatih/color/blob/master/color.go
Index ¶
- Variables
- func Black(format string, a ...interface{})
- func BlackString(format string, a ...interface{}) string
- func Blue(format string, a ...interface{})
- func BlueString(format string, a ...interface{}) string
- func Cyan(format string, a ...interface{})
- func CyanString(format string, a ...interface{}) string
- func Green(format string, a ...interface{})
- func GreenString(format string, a ...interface{}) string
- func HiBlack(format string, a ...interface{})
- func HiBlackString(format string, a ...interface{}) string
- func HiBlue(format string, a ...interface{})
- func HiBlueString(format string, a ...interface{}) string
- func HiCyan(format string, a ...interface{})
- func HiCyanString(format string, a ...interface{}) string
- func HiGreen(format string, a ...interface{})
- func HiGreenString(format string, a ...interface{}) string
- func HiMagenta(format string, a ...interface{})
- func HiMagentaString(format string, a ...interface{}) string
- func HiRed(format string, a ...interface{})
- func HiRedString(format string, a ...interface{}) string
- func HiWhite(format string, a ...interface{})
- func HiWhiteString(format string, a ...interface{}) string
- func HiYellow(format string, a ...interface{})
- func HiYellowString(format string, a ...interface{}) string
- func Magenta(format string, a ...interface{})
- func MagentaString(format string, a ...interface{}) string
- func Red(format string, a ...interface{})
- func RedString(format string, a ...interface{}) string
- func Unset()
- func White(format string, a ...interface{})
- func WhiteString(format string, a ...interface{}) string
- func Yellow(format string, a ...interface{})
- func YellowString(format string, a ...interface{}) string
- type Attribute
- type Color
- func (c *Color) Add(value ...Attribute) *Color
- func (c *Color) DisableColor()
- func (c *Color) EnableColor()
- func (c *Color) Equals(c2 *Color) bool
- func (c *Color) Fprint(w io.Writer, a ...interface{}) (n int, err error)
- func (c *Color) FprintFunc() func(w io.Writer, a ...interface{})
- func (c *Color) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (c *Color) FprintfFunc() func(w io.Writer, format string, a ...interface{})
- func (c *Color) Fprintln(w io.Writer, a ...interface{}) (n int, err error)
- func (c *Color) FprintlnFunc() func(w io.Writer, a ...interface{})
- func (c *Color) Print(a ...interface{}) (n int, err error)
- func (c *Color) PrintFunc() func(a ...interface{})
- func (c *Color) Printf(format string, a ...interface{}) (n int, err error)
- func (c *Color) PrintfFunc() func(format string, a ...interface{})
- func (c *Color) Println(a ...interface{}) (n int, err error)
- func (c *Color) PrintlnFunc() func(a ...interface{})
- func (c *Color) Set() *Color
- func (c *Color) Sprint(a ...interface{}) string
- func (c *Color) SprintFunc() func(a ...interface{}) string
- func (c *Color) Sprintf(format string, a ...interface{}) string
- func (c *Color) SprintfFunc() func(format string, a ...interface{}) string
- func (c *Color) Sprintln(a ...interface{}) string
- func (c *Color) SprintlnFunc() func(a ...interface{}) string
Constants ¶
This section is empty.
Variables ¶
var ( // NoColor defines if the output is colorized or not. It's dynamically set to // false or true based on the stdout's file descriptor referring to a terminal // or not. This is a global option and affects all colors. For more control // over each color block use the methods DisableColor() individually. NoColor = os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) // Output defines the standard output of the print functions. By default // os.Stdout is used. Output = colorable.NewColorableStdout() // Error defines a color supporting writer for os.Stderr. Error = colorable.NewColorableStderr() )
var ( // Section is used for sections Section = New(FgHiYellow, Underline).Sprintf // Primary is used for primary texts Primary = HiCyanString // Secondary is used for secondary texts Secondary = HiGreenString // Flag is used for global and local flags Flag = GreenString // Separator is used for separators Separator = RedString // R resets the color R = New(Reset).Sprintf("") )
Functions ¶
func Black ¶
func Black(format string, a ...interface{})
Black is a convenient helper function to print with black foreground. A newline is appended to format by default.
func BlackString ¶
BlackString is a convenient helper function to return a string with black foreground.
func Blue ¶
func Blue(format string, a ...interface{})
Blue is a convenient helper function to print with blue foreground. A newline is appended to format by default.
func BlueString ¶
BlueString is a convenient helper function to return a string with blue foreground.
func Cyan ¶
func Cyan(format string, a ...interface{})
Cyan is a convenient helper function to print with cyan foreground. A newline is appended to format by default.
func CyanString ¶
CyanString is a convenient helper function to return a string with cyan foreground.
func Green ¶
func Green(format string, a ...interface{})
Green is a convenient helper function to print with green foreground. A newline is appended to format by default.
func GreenString ¶
GreenString is a convenient helper function to return a string with green foreground.
func HiBlack ¶
func HiBlack(format string, a ...interface{})
HiBlack is a convenient helper function to print with hi-intensity black foreground. A newline is appended to format by default.
func HiBlackString ¶
HiBlackString is a convenient helper function to return a string with hi-intensity black foreground.
func HiBlue ¶
func HiBlue(format string, a ...interface{})
HiBlue is a convenient helper function to print with hi-intensity blue foreground. A newline is appended to format by default.
func HiBlueString ¶
HiBlueString is a convenient helper function to return a string with hi-intensity blue foreground.
func HiCyan ¶
func HiCyan(format string, a ...interface{})
HiCyan is a convenient helper function to print with hi-intensity cyan foreground. A newline is appended to format by default.
func HiCyanString ¶
HiCyanString is a convenient helper function to return a string with hi-intensity cyan foreground.
func HiGreen ¶
func HiGreen(format string, a ...interface{})
HiGreen is a convenient helper function to print with hi-intensity green foreground. A newline is appended to format by default.
func HiGreenString ¶
HiGreenString is a convenient helper function to return a string with hi-intensity green foreground.
func HiMagenta ¶
func HiMagenta(format string, a ...interface{})
HiMagenta is a convenient helper function to print with hi-intensity magenta foreground. A newline is appended to format by default.
func HiMagentaString ¶
HiMagentaString is a convenient helper function to return a string with hi-intensity magenta foreground.
func HiRed ¶
func HiRed(format string, a ...interface{})
HiRed is a convenient helper function to print with hi-intensity red foreground. A newline is appended to format by default.
func HiRedString ¶
HiRedString is a convenient helper function to return a string with hi-intensity red foreground.
func HiWhite ¶
func HiWhite(format string, a ...interface{})
HiWhite is a convenient helper function to print with hi-intensity white foreground. A newline is appended to format by default.
func HiWhiteString ¶
HiWhiteString is a convenient helper function to return a string with hi-intensity white foreground.
func HiYellow ¶
func HiYellow(format string, a ...interface{})
HiYellow is a convenient helper function to print with hi-intensity yellow foreground. A newline is appended to format by default.
func HiYellowString ¶
HiYellowString is a convenient helper function to return a string with hi-intensity yellow foreground.
func Magenta ¶
func Magenta(format string, a ...interface{})
Magenta is a convenient helper function to print with magenta foreground. A newline is appended to format by default.
func MagentaString ¶
MagentaString is a convenient helper function to return a string with magenta foreground.
func Red ¶
func Red(format string, a ...interface{})
Red is a convenient helper function to print with red foreground. A newline is appended to format by default.
func Unset ¶
func Unset()
Unset resets all escape attributes and clears the output. Usually should be called after Set().
func White ¶
func White(format string, a ...interface{})
White is a convenient helper function to print with white foreground. A newline is appended to format by default.
func WhiteString ¶
WhiteString is a convenient helper function to return a string with white foreground.
func Yellow ¶
func Yellow(format string, a ...interface{})
Yellow is a convenient helper function to print with yellow foreground. A newline is appended to format by default.
func YellowString ¶
YellowString is a convenient helper function to return a string with yellow foreground.
Types ¶
type Attribute ¶
type Attribute int
Attribute defines a single SGR Code
const ( Reset Attribute = iota Bold Faint Italic Underline BlinkSlow BlinkRapid ReverseVideo Concealed CrossedOut )
Base attributes
Foreground text colors
const ( FgHiBlack Attribute = iota + 90 FgHiRed FgHiGreen FgHiYellow FgHiBlue FgHiMagenta FgHiCyan FgHiWhite )
Foreground Hi-Intensity text colors
Background text colors
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color defines a custom color object which is defined by SGR parameters.
func Set ¶
Set sets the given parameters immediately. It will change the color of output with the given SGR parameters until color.Unset() is called.
func (*Color) Add ¶
Add is used to chain SGR parameters. Use as many as parameters to combine and create custom color objects. Example: Add(color.FgRed, color.Underline).
func (*Color) DisableColor ¶
func (c *Color) DisableColor()
DisableColor disables the color output. Useful to not change any existing code and still being able to output. Can be used for flags like "--no-color". To enable back use EnableColor() method.
func (*Color) EnableColor ¶
func (c *Color) EnableColor()
EnableColor enables the color output. Use it in conjunction with DisableColor(). Otherwise this method has no side effects.
func (*Color) 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. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.
func (*Color) FprintFunc ¶
FprintFunc returns a new function that prints the passed arguments as colorized with color.Fprint().
func (*Color) Fprintf ¶
Fprintf formats according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.
func (*Color) FprintfFunc ¶
FprintfFunc returns a new function that prints the passed arguments as colorized with color.Fprintf().
func (*Color) 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. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.
func (*Color) FprintlnFunc ¶
FprintlnFunc returns a new function that prints the passed arguments as colorized with color.Fprintln().
func (*Color) 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. This is the standard fmt.Print() method wrapped with the given color.
func (*Color) PrintFunc ¶
func (c *Color) PrintFunc() func(a ...interface{})
PrintFunc returns a new function that prints the passed arguments as colorized with color.Print().
func (*Color) 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. This is the standard fmt.Printf() method wrapped with the given color.
func (*Color) PrintfFunc ¶
PrintfFunc returns a new function that prints the passed arguments as colorized with color.Printf().
func (*Color) 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. This is the standard fmt.Print() method wrapped with the given color.
func (*Color) PrintlnFunc ¶
func (c *Color) PrintlnFunc() func(a ...interface{})
PrintlnFunc returns a new function that prints the passed arguments as colorized with color.Println().
func (*Color) SprintFunc ¶
SprintFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprint(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output, example:
put := New(FgYellow).SprintFunc() fmt.Fprintf(color.Output, "This is a %s", put("warning"))
func (*Color) SprintfFunc ¶
SprintfFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprintf(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output.
func (*Color) Sprintln ¶
Sprintln is just like Println, but returns a string instead of printing it.
func (*Color) SprintlnFunc ¶
SprintlnFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprintln(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output.