ansi

package
v0.0.0-...-9d255cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func Fprint(w io.Writer, a ...any) (n int, err error)

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

func Fprintf(w io.Writer, format string, a ...any) (n int, err error)

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

func Fprintln(w io.Writer, a ...any) (n int, err error)

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

func Print(a ...any) (n int, err error)

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

func Printf(format string, a ...any) (n int, err error)

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

func Println(a ...any) (n int, err error)

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

func Sprint(a ...any) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.

func Sprintf

func Sprintf(format string, a ...any) string

Sprintf formats according to a format specifier and returns the resulting string.

func Sprintln

func Sprintln(a ...any) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL