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

term

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package term styles the bide command's text output for a terminal: a check mark and green for what passed, a cross and red for what failed, amber for a warning or a gate, bold cyan for a path or address to act on, dim for secondary detail. Status is never carried by color alone: a styled line keeps its words, and adds a mark (✓ or ✗) beside them.

Color is on for a terminal only (an *os.File that is a character device), and off when NO_COLOR is set to anything or TERM is dumb. On Windows it is on only where the terminal is known to read ANSI escapes (Windows Terminal, ConEmu, ANSICON, VS Code, or a TERM such as xterm-256color). A -color=always or -color=never flag overrides all of that. Output to a file or a pipe is plain, so a script or CI log reads the same text it always did.

The package is the standard library only, so bide audit's build stays core-only.

Index

Constants

View Source
const FlagUsage = "`when` to color the output: auto (the default: on a terminal, unless NO_COLOR is set or TERM is dumb), always or never"

FlagUsage is the help text of every -color flag.

Variables

View Source
var IsTerminal = isTerminal

IsTerminal reports whether w is a terminal. A test of a command's terminal output replaces it, to check what NO_COLOR and TERM do on a terminal without opening one.

Functions

This section is empty.

Types

type Mode

type Mode int

Mode is the -color flag: auto (the default), always or never.

const (
	// Auto colors a terminal, unless NO_COLOR is set or TERM is dumb.
	Auto Mode = iota
	// Always colors whatever the output is.
	Always
	// Never colors nothing.
	Never
)

func Flag

func Flag(fs *flag.FlagSet) *Mode

Flag defines a -color flag on fs and returns its value.

func (*Mode) Set

func (m *Mode) Set(s string) error

Set reads a -color value.

func (Mode) String

func (m Mode) String() string

String is the mode as -color reads it.

type Style

type Style struct {
	// contains filtered or unexported fields
}

Style styles text, or leaves it as it is when color is off. The zero Style is off.

func For

func For(w io.Writer, m Mode) Style

For is the style for output written to w under mode m.

func New

func New(on bool) Style

New is a style with color on or off, for a caller that has already decided.

func (Style) Bang

func (s Style) Bang() string

Bang is an amber exclamation mark and a space when color is on, and nothing when it is off.

func (Style) Blue

func (s Style) Blue(t string) string

Blue is blue, for the one state the roles do not cover: a halt resolved.

func (Style) Bold

func (s Style) Bold(t string) string

Bold is bold, for emphasis no role names.

func (Style) BoldFail

func (s Style) BoldFail(t string) string

BoldFail is a verdict that does not hold, or a weakened gate: bold red.

func (Style) BoldOK

func (s Style) BoldOK(t string) string

BoldOK is a verdict that holds: bold green.

func (Style) Cross

func (s Style) Cross() string

Cross is a red cross and a space when color is on, and nothing when it is off.

func (Style) Cyan

func (s Style) Cyan(t string) string

Cyan is cyan, for a neutral step.

func (Style) Dim

func (s Style) Dim(t string) string

Dim is secondary detail: a digest, a count, a file name repeated on every line.

func (Style) ErrorPrefix

func (s Style) ErrorPrefix() string

ErrorPrefix is a bold red "error:" and a space when color is on, and nothing when it is off: an error line on a terminal opens with it, and a piped one stays as it was.

func (Style) Fail

func (s Style) Fail(t string) string

Fail is what failed or was violated: red.

func (Style) Heading

func (s Style) Heading(t string) string

Heading is a heading: bold.

func (Style) Hint

func (s Style) Hint(msg, sep string) string

Hint dims what follows the first sep in msg, a "what to do next" the message carries after a colon or a semicolon, and leaves msg as it is when color is off or msg has no sep. sep stays with the plain part.

func (Style) OK

func (s Style) OK(t string) string

OK is what passed or verified: green.

func (Style) On

func (s Style) On() bool

On reports whether s colors.

func (Style) Pass

func (s Style) Pass() string

Pass is a green check mark and a space when color is on, and nothing when it is off: a colored line carries a mark beside its words, a plain line stays as it was.

func (Style) Path

func (s Style) Path(t string) string

Path is a path, an address or a command to act on: bold cyan.

func (Style) Warn

func (s Style) Warn(t string) string

Warn is a warning, a halt or an approval gate: amber.

Jump to

Keyboard shortcuts

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