Documentation
¶
Overview ¶
Package output renders command results as human-readable text, JSON or YAML. Commands pass a view model (with json tags) plus a text renderer; machine formats are derived from the view model only, so the JSON schema is what the view model declares and never an internal Go structure.
Index ¶
- func RenderTree(w io.Writer, n *Node) error
- func VisibleWidth(s string) int
- func WriteJSON(w io.Writer, v any) error
- func WriteYAML(w io.Writer, v any) error
- type Format
- type KV
- type Node
- type Printer
- type Style
- func (s Style) Blue(v string) string
- func (s Style) Bold(v string) string
- func (s Style) Cyan(v string) string
- func (s Style) Dim(v string) string
- func (s Style) Green(v string) string
- func (s Style) Level(level string) string
- func (s Style) Red(v string) string
- func (s Style) Yellow(v string) string
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderTree ¶
RenderTree writes n with box-drawing connectors.
func VisibleWidth ¶
VisibleWidth returns the printed width of s, ignoring ANSI sequences.
Types ¶
type Format ¶
type Format string
Format selects the output encoding.
func ParseFormat ¶
ParseFormat validates a --format value. "table" is an alias of text.
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV renders aligned "Label: value" blocks, optionally under headings. Empty values are skipped so renderers can add optional fields freely.
type Printer ¶
Printer writes results to Out and diagnostics to Err.
func New ¶
New creates a printer. Colour is enabled only for terminals, and never when NO_COLOR is set or noColor is true.
func (*Printer) Emit ¶
Emit writes v in the selected machine format, or calls text for text/raw output. text may be nil when a command has no human rendering.
type Style ¶
type Style struct{ Enabled bool }
Style applies ANSI styling when enabled.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table renders aligned columns. Cells may contain ANSI colour codes.