Documentation
¶
Overview ¶
Package ansi provides a light abstraction around ANSI color codes.
Index ¶
- Constants
- Variables
- func ColorWriter(w io.Writer) io.Writer
- func DisableColors()
- func Eprint(args ...any) (int, error)
- func Eprintf(format string, args ...any) (int, error)
- func Eprintln(args ...any) (int, error)
- func Fprint(w io.Writer, args ...any) (int, error)
- func Fprintf(w io.Writer, format string, args ...any) (int, error)
- func Fprintln(w io.Writer, args ...any) (int, error)
- func Fsprintf(w io.Writer, format string, args ...any) string
- func IsColorable(w io.Writer) bool
- func NoColorWriter(w io.Writer) io.Writer
- func Print(args ...any) (int, error)
- func Printf(format string, args ...any) (int, error)
- func Println(args ...any) (int, error)
- func Sprintf(format string, args ...any) string
- func StripFormat(format string) string
- type Attribute
- type Display
- type Formatter
Constants ¶
const ( // Reset is an ANSI attribute for resetting formatting Reset attribute = 0 // Bold is an ANSI attribute for setting a bold format Bold attribute = 1 // Faint is an ANSI attribute for setting a faint format Faint attribute = 2 // Italice is an ANSI attribute for setting an italic format Italic attribute = 3 // Underline is an ANSI attribute for setting an underline format Underline attribute = 4 // DefaultFont is an ANSI attribute for setting the default font DefaultFont attribute = 10 // FGBlack is an ANSI attribute for the foreground color black FGBlack attribute = 30 // FGRed is an ANSI attribute for the foreground color red FGRed attribute = 31 // FGGreen is an ANSI attribute for the foreground color green FGGreen attribute = 32 // FGYellow is an ANSI attribute for the foreground color yellow FGYellow attribute = 33 // FGBlue is an ANSI attribute for the foreground color blue FGBlue attribute = 34 // FGMagenta is an ANSI attribute for the foreground color magenta FGMagenta attribute = 35 // FGCyan is an ANSI attribute for the foreground color cyan FGCyan attribute = 36 // FGWhite is an ANSI attribute for the foreground color white FGWhite attribute = 37 // FGGray is an ANSI attribute for the foreground color gray FGGray attribute = 90 // FGBrightRed is an ANSI attribute for the foreground color brightred FGBrightRed attribute = 91 // FGBrightGreen is an ANSI attribute for the foreground color brightgreen FGBrightGreen attribute = 92 // FGBrightYellow is an ANSI attribute for the foreground color brightyellow FGBrightYellow attribute = 93 // FGBrightBlue is an ANSI attribute for the foreground color brightblue FGBrightBlue attribute = 94 // FGBrightMagenta is an ANSI attribute for the foreground color brightmagenta FGBrightMagenta attribute = 95 // FGBrightCyan is an ANSI attribute for the foreground color brightcyan FGBrightCyan attribute = 96 // FGBrightWhite is an ANSI attribute for the foreground color brightwhite FGBrightWhite attribute = 97 // FGDefault is an ANSI attribute for setting the default foreground color FGDefault attribute = 39 // BGBlack is an ANSI attribute for the background color black BGBlack attribute = 40 // BGRed is an ANSI attribute for the background color red BGRed attribute = 41 // BGGreen is an ANSI attribute for the background color green BGGreen attribute = 42 // BGYellow is an ANSI attribute for the background color yellow BGYellow attribute = 43 // BGBlue is an ANSI attribute for the background color blue BGBlue attribute = 44 // BGMagenta is an ANSI attribute for the background color magenta BGMagenta attribute = 45 // BGCyan is an ANSI attribute for the background color cyan BGCyan attribute = 46 // BGWhite is an ANSI attribute for the background color white BGWhite attribute = 47 // BGGray is an ANSI attribute for the background color gray BGGray attribute = 100 // BGBrightRed is an ANSI attribute for the background color brightred BGBrightRed attribute = 101 // BGBrightGreen is an ANSI attribute for the background color brightgreen BGBrightGreen attribute = 102 // BGBrightYellow is an ANSI attribute for the background color brightyellow BGBrightYellow attribute = 103 // BGBrightBlue is an ANSI attribute for the background color brightblue BGBrightBlue attribute = 104 // BGBrightMagenta is an ANSI attribute for the background color brightmagenta BGBrightMagenta attribute = 105 // BGBrightCyan is an ANSI attribute for the background color brightcyan BGBrightCyan attribute = 106 // BGBrightWhite is an ANSI attribute for the background color brightwhite BGBrightWhite attribute = 107 // BGDefault is an ANSI attribute for setting the default background color BGDefault attribute = 49 )
const ( // ControlSequenceIntroducer is the prefix for ANSI escape commands. ControlSequenceIntroducer = "\033[" // ControlCode is a rune representing the ANSI control code (0x1B, or 033). ControlCode rune = 033 // Separator is the separator between different control codes. Separator = ';' // SGR is the suffix code for the Select Graphics Renderer control codes. SGRSuffix = 'm' )
Variables ¶
var None = Format()
Functions ¶
func ColorWriter ¶
ColorWriter creates an io.Writer that forces writing of colors, even if it's disabled or not currently allowed.
func Eprint ¶
Eprint behaves like fmt.Print, except that it will conditionally support color formatting depending if os.Stderr is colorable.
func Eprintf ¶
Eprintf behaves like fmt.Printf, except that it will conditionally support color formatting depending if os.Stderr is colorable.
func Eprintln ¶
Eprintln behaves like fmt.Println, except that it will conditionally support color formatting depending if os.Stderr is colorable.
func Fprint ¶
Fprint behaves like fmt.Fprint, except that it will conditionally support color formatting depending on whether the Writer is colorable.
func Fprintf ¶
Fprintf behaves like fmt.Fprintf, except that it will conditionally support color formatting depending on whether the Writer is colorable.
func Fprintln ¶
Fprintln behaves like fmt.Fprintln, except that it will conditionally support color formatting depending on whether the Writer is colorable.
func Fsprintf ¶
Fsprintf behaves like fmt.Sprintf, except that it will conditionally support color formatting depending on whether the Writer is colorable.
func IsColorable ¶
IsColorable checks whether the specified Writer is a colorable output destination.
This will return true either if the Writer is a TTY with colors enabled, or if the writer is an explicit colorable writer.
func NoColorWriter ¶
NoColorWriter creates an io.Writer that forces writing of colors to be disabled.
func Print ¶
print behaves like fmt.Print, except that it will conditionally support color formatting depending if os.Stdout is colorable.
func Printf ¶
Printf behaves like fmt.Printf, except that it will conditionally support color formatting depending if os.Stdout is colorable.
func Println ¶
Println behaves like fmt.Println, except that it will conditionally support color formatting depending if os.Stdout is colorable.
func Sprintf ¶
Sprintf behaves exactly like fmt.Sprintf, except it will disable color codes if NOCOLOR or NO_COLOR are set.
Note: ansi.Sprintf cannot obey explicit colored writers since it coalesces down to a single string type. If NOCOLOR is defined, then Sprintf behaves identically to fmt.Sprintf.
func StripFormat ¶
StripFormat will remove all ANSI escape codes from the input format string.
Types ¶
type Attribute ¶
type Attribute interface { Display // contains filtered or unexported methods }
Attribute is a unit type which represents individual ANSI formatting attributes.