Documentation ¶
Overview ¶
Package colors contains color-related utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Enabled ¶
func Enabled() bool
Enabled returns whether it is ok to write colorized output to stdout or stderr. It's true only if all the following conditions are met:
- The environment variable NO_COLOR is not set.
- The environment variable TERM is not equal to "dumb".
- stdout and stderr are both terminals.
Types ¶
type Atom ¶
type Atom struct { S string // the text Underline bool // is it underlined? Bold bool // is it bold? Color Code // text color }
An Atom is a segment of text with a single formatting style.
type Code ¶
type Code string
Code represents an ANSI escape code for colors and formatting.
type Tabularizer ¶
type Tabularizer struct {
// contains filtered or unexported fields
}
A Tabularizer produces pretty-printed tabularized text. Unlike tabwriter.Writer 1, Tabularizer properly handles text with ANSI escape codes. Here's what an example table looks like:
╭───────────────────────╮ │ CATS │ ├────────┬─────┬────────┤ │ NAME │ AGE │ COLOR │ ├────────┼─────┼────────┤ │ belle │ 1y │ tortie │ │ sidney │ 2y │ calico │ │ dakota │ 8m │ tuxedo │ ╰────────┴─────┴────────╯
The table format comes from duf 2.
func NewTabularizer ¶
NewTabularizer returns a new tabularizer. The provided dim function determines which columns in a row, if any, are dimmed.
func (*Tabularizer) Flush ¶
func (t *Tabularizer) Flush()
Flush writes all buffered rows. Flush should only be called once, after all rows have been written.
func (*Tabularizer) Row ¶
func (t *Tabularizer) Row(values ...any)
Row buffers a new Row to be tabularized. The Row isn't written until Flush is called. Note that every Row reported to a tabularizer must be the same length. A value can be a text, atom, string, or fmt.Stringer.