term

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBrokenPipe

func IsBrokenPipe(err error) bool

IsBrokenPipe reports whether err comes from writing to a pipe whose reader has gone, as when output goes to `head`.

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal reports whether w is a terminal.

func Rows

func Rows(rows [][]string) [][]Cell

Rows turns rows of plain text into rows of cells for Table.

func Sanitize

func Sanitize(s string) string

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

func Table(header []string, rows [][]Cell) string

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

func UseColor(mode ColorMode, lookup func(string) (string, bool), isTTY bool) bool

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.

func Wrap

func Wrap(s string, width int, first, rest string) string

Wrap breaks s at spaces so each line fits width display cells, starting the first line with first and the others with rest. A word longer than the line stays whole, so URLs keep working. A width of 0 or one too small for the prefixes leaves s on one line.

func Writer

func Writer(w io.Writer, p colorprofile.Profile) io.Writer

Writer wraps w so styled text written to it follows profile p.

Types

type Cell

type Cell struct {
	Text string
	Tone Tone
}

Cell is one table cell.

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

func ParseColorMode(s string) (ColorMode, error)

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 Detect

func Detect(w io.Writer, mode ColorMode, lookup func(string) (string, bool)) Stream

Detect works out the Stream for w. lookup reads the environment.

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

func NoteTone(line string) Tone

NoteTone is the tone of a note line by its label: Warn for "warning: ...", Bad for "error: ..." and "<target>: error: ...", Plain otherwise.

func (Tone) Paint

func (t Tone) Paint(s string) string

Paint returns s in tone t, with control characters in s made visible by Sanitize.

func (Tone) Style

func (t Tone) Style() lipgloss.Style

Style returns the lipgloss style of t.

Jump to

Keyboard shortcuts

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