Documentation
¶
Overview ¶
Package ansi implements formatting of output text using ANSI escape sequences by wrapping the fmt package.
Format strings (or string arguments to functions which don't accept a format string) can contain placeholders of the form ${NAME}, where NAME is the name of an ANSI code. The placeholder will be replaced with the corresponding ANSI escape sequence in the output. For functions which accept a format string and arguments, the ${NAME} placeholders are replaced after the arguments have been interpolated into the format string. Placeholders can therefore can be dynamically defined.
The following ANSI codes are supported:
- RESET
- BOLD
- FAINT
- ITALIC
- UNDERLINE
- BLINKING
- INVERSE
- HIDDEN
- STRIKETHROUGH
- RESET_BOLD
- RESET_ITALIC
- RESET_UNDERLINE
- RESET_BLINKING
- RESET_INVERSE
- RESET_HIDDEN
- RESET_STRIKETHROUGH
- BLACK
- RED
- GREEN
- YELLOW
- BLUE
- MAGENTA
- CYAN
- WHITE
- DEFAULT
Index ¶
- Variables
- func Fprint(w io.Writer, a ...any) (n int, err error)
- func Fprintf(w io.Writer, format string, a ...any) (n int, err error)
- func Fprintln(w io.Writer, a ...any) (n int, err error)
- func Print(a ...any) (n int, err error)
- func Printf(format string, a ...any) (n int, err error)
- func Println(a ...any) (n int, err error)
- func Sprint(a ...any) string
- func Sprintf(format string, a ...any) string
- func Sprintln(a ...any) string
Constants ¶
This section is empty.
Variables ¶
var Enabled = term.IsTerminal(int(os.Stdout.Fd())) && term.IsTerminal(int(os.Stderr.Fd()))
Enabled determines whether ANSI escape sequences will be output by the functions in this package. If stdout and stderr are both connected to a terminal, this will be true.
Functions ¶
func 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 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 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 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 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 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 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.
Types ¶
This section is empty.