Documentation
¶
Overview ¶
Package term decides how output looks on each stream (terminal detection, color, width) and renders the styled text and tables of the tty format.
Index ¶
- func IsBrokenPipe(err error) bool
- func IsTerminal(w io.Writer) bool
- func Rows(rows [][]string) [][]Cell
- func Sanitize(s string) string
- func Table(header []string, rows [][]Cell) string
- func UseColor(mode ColorMode, lookup func(string) (string, bool), isTTY bool) bool
- func Wrap(s string, width int, first, rest string) string
- func Writer(w io.Writer, p colorprofile.Profile) io.Writer
- type Cell
- type ColorMode
- type Stream
- type Tone
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBrokenPipe ¶
IsBrokenPipe reports whether err comes from writing to a pipe whose reader has gone, as when output goes to `head`.
func Sanitize ¶
Sanitize makes control characters in text from outside the program visible, so a release note or a tag value can't move the cursor, set the title or write the clipboard. Tabs and newlines stay; a carriage return before a newline is dropped. Other C0 characters and DEL become caret notation (^[ for ESC), and C1 characters become ^[ plus their 7-bit form.
func Table ¶
Table renders an optional header row and rows as left-aligned columns two spaces apart, with no borders. It measures display cells, so wide characters and styles keep the columns aligned, and it never cuts a cell. Cell text goes through Sanitize, and lines end without spaces.
func UseColor ¶
UseColor reports whether a stream gets ANSI styles. The first rule that applies wins: --color always or never, a non-empty NO_COLOR (off), CLICOLOR_FORCE or FORCE_COLOR set to anything but empty, 0 or false (on), CLICOLOR=0 or TERM=dumb (off), then whether the stream is a terminal.
Types ¶
type ColorMode ¶
type ColorMode string
ColorMode is the --color flag value.
const ( ColorAuto ColorMode = "auto" ColorAlways ColorMode = "always" ColorNever ColorMode = "never" )
Color modes.
func ParseColorMode ¶
ParseColorMode validates a --color value.
type Stream ¶
type Stream struct {
TTY bool // a terminal, a Cygwin or MSYS pty included
Color bool // ANSI styles are on
Width int // columns to wrap prose at; 0 means don't wrap
}
Stream says how to write to one output stream. Detect fills it once at startup.
func (Stream) Profile ¶
func (s Stream) Profile() colorprofile.Profile
Profile is the color profile that writes styled text to this stream: ANSI with color, otherwise none, which strips every escape sequence.
type Tone ¶
type Tone uint8
Tone is what a piece of styled text means. Each tone uses one of the 16 basic ANSI colors, so it follows the user's terminal theme, and the text itself always carries the meaning as well.
const ( Plain Tone = iota Good // green: current, clean, ok Warn // yellow: behind, drifted, needs a look Bad // red: errors, vulnerabilities, unmanaged resources Severe // bold red: breaking changes, end of life, known exploited Muted // faint: skipped, excluded, low severity Heading // bold: section and tool headings )
Tones.
func NoteTone ¶
NoteTone is the tone of a note line by its label: Warn for "warning: ...", Bad for "error: ..." and "<target>: error: ...", Plain otherwise.