Help us shape the future of Go! Take the 2026 Go Developer Survey

term

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package term renders plain, readable terminal output: optional color, aligned columns, wrapped paragraphs and human units. Color is used only when the writer is a terminal and the environment does not opt out.

Index

Constants

View Source
const Width = 96

Width is the column count text is wrapped to.

Variables

This section is empty.

Functions

func Bytes

func Bytes(n int) string

Bytes formats a byte count in binary units.

func DidYouMean added in v0.1.0

func DidYouMean(word string, candidates []string) string

DidYouMean is " Did you mean x?" for a close candidate, else "".

func Duration

func Duration(d time.Duration) string

Duration formats a compile-scale duration.

func Pad

func Pad(text string, width int) string

Pad right-pads text to width visible runes.

func Plural

func Plural(n int, word string) string

Plural returns "1 file", "2 files".

func Suggest added in v0.1.0

func Suggest(word string, candidates []string) string

Suggest is the candidate closest to a mistyped word, or "" when none is close enough to be what was meant: at most a third of its letters apart.

func Wrap

func Wrap(text string, width int, indent string) string

Wrap breaks text into lines of at most width runes, not counting indent, which prefixes every continuation line. Words longer than a line stay whole.

Types

type Style

type Style struct{ Color bool }

Style renders text attributes as ANSI escapes, or not at all.

func For

func For(w io.Writer) Style

For picks colors for w: on for terminals, off for pipes and files, NO_COLOR and TERM=dumb. FORCE_COLOR=0 or false (case-insensitive) disables color; any other non-empty FORCE_COLOR value turns it on regardless.

func (Style) Bold

func (s Style) Bold(text string) string

func (Style) Cyan

func (s Style) Cyan(text string) string

func (Style) Dim

func (s Style) Dim(text string) string

func (Style) Green

func (s Style) Green(text string) string

func (Style) Red

func (s Style) Red(text string) string

func (Style) Yellow

func (s Style) Yellow(text string) string

Jump to

Keyboard shortcuts

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