term

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package term renders tops output: errors, symbols, tables and JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorEnabled

func ColorEnabled(getenv func(string) string, isTerminal bool) bool

ColorEnabled reports whether output may use colour: only on a terminal, and never when NO_COLOR is set or TERM is dumb.

func ExitCode

func ExitCode(err error) int

ExitCode maps an error to the process exit code (TRD "Exit codes").

func Mark

func Mark(s Symbol, unicode bool) string

Mark returns s as printed: a UTF-8 symbol, or a 4-character word when the locale is not UTF-8.

func Paint

func Paint(text string, s Symbol, color bool) string

Paint colours text with the color of s, or returns it unchanged when color is false.

func PrintError

func PrintError(w io.Writer, style Style, err error) error

PrintError writes err for the operator: what happened, why, and how to fix it.

func UnicodeLocale

func UnicodeLocale(getenv func(string) string) bool

UnicodeLocale reports whether the locale allows UTF-8 output. LC_ALL overrides LC_CTYPE, which overrides LANG; the first one that is set decides.

func WriteErrorJSON

func WriteErrorJSON(w io.Writer, version string, err error) error

WriteErrorJSON writes err as one JSON document of kind Error. Errors that are not a UserError get the code "unexpected".

func WriteJSON

func WriteJSON(w io.Writer, doc any) error

WriteJSON writes doc as one JSON document followed by a newline. <, > and & stay readable: tops output never goes into HTML.

Types

type Exit

type Exit struct {
	Code int
}

Exit is an exit code a command chose itself, such as the helper's 0, 1 or 2

func (*Exit) Error

func (e *Exit) Error() string

type Reported

type Reported struct {
	Err error
}

Reported wraps an error whose details a command has already written as its result, such as the Validation document of an invalid spec. main uses it only for the exit code.

func (*Reported) Error

func (r *Reported) Error() string

func (*Reported) Unwrap

func (r *Reported) Unwrap() error

Unwrap lets errors.As and ExitCode see the wrapped error.

type Style

type Style struct {
	Unicode bool
	Color   bool
}

Style says how output may be decorated on the stream it is written to.

func (Style) Mark

func (st Style) Mark(s Symbol) string

Mark returns s as printed in this style: symbol or word, coloured or plain.

type Symbol

type Symbol int

Symbol is the status marker printed at the start of a line.

const (
	OK Symbol = iota
	Warn
	Fail
	Skip
	Add
	Remove
	Change
)

The status markers from the design brief, then the change markers of plan, diff and drift.

type UserError

type UserError struct {
	Code string
	What string
	Why  string
	Fix  string
}

UserError is an error meant for the operator: what happened, why, and how to fix it. Code is stable and appears in --json output.

func (*UserError) Error

func (e *UserError) Error() string

Jump to

Keyboard shortcuts

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