output

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: GPL-3.0 Imports: 16 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 output renders API results as kubectl-style tables or as JSON/YAML.

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorAccent  = lipgloss.Color("#D6336C") // titles, section headers
	ColorBranch  = lipgloss.Color("#228BE6") // nested object/array keys
	ColorKey     = lipgloss.Color("#868E96") // field labels
	ColorBorder  = lipgloss.Color("#5C5F77") // table borders
	ColorSuccess = lipgloss.Color("#40C057") // healthy/true
	ColorDanger  = lipgloss.Color("#E03131") // error/failed
	ColorMuted   = lipgloss.Color("#868E96") // disabled/pending/false
	ColorNumber  = lipgloss.Color("#F08C00") // numeric values

	ColorMatchBG   = lipgloss.Color("#FAB005") // search match background
	ColorMatchFG   = lipgloss.Color("#000000") // search match foreground
	ColorCurrentBG = lipgloss.Color("#E64980") // active match background
	ColorCurrentFG = lipgloss.Color("#FFFFFF") // active match foreground
)

Palette used across the table, describe, and interactive-viewer renderers. Colors are chosen to read clearly on both light and dark terminal backgrounds (mid-range luminance, avoiding near-white/near-black) rather than adapting live to the detected background, since querying the terminal for its background color adds latency and can hang on some terminals/multiplexers.

View Source
var ErrUnsupportedFormat = errors.New("unsupported output format")

ErrUnsupportedFormat is returned by Parse for an unknown output format.

Functions

func BoolColor

func BoolColor(value string) color.Color

BoolColor colors a "true"/"false" cell green/gray.

func IsTerminal added in v0.2.0

func IsTerminal(w io.Writer) bool

IsTerminal reports whether w is a terminal, so callers can decide between a styled, grouped presentation and a flat, pipe-safe one.

func PlainRow

func PlainRow(row Row) string

PlainRow renders a row without any styling, used by the interactive viewer to index lines for case-insensitive search.

func PrintSectionHeader added in v0.2.0

func PrintSectionHeader(w io.Writer, text string) error

PrintSectionHeader writes a bold, accent-colored label (e.g. a namespace grouping the table printed below it), downsampled to w's color profile.

func RenderDescribe

func RenderDescribe(w io.Writer, title string, rows []Row) error

RenderDescribe writes a colorized static view of rows to w. Color is downsampled (or stripped entirely) to match w's actual color profile, so pipes, redirected files, and NO_COLOR all fall back to plain text.

func RenderRow

func RenderRow(s DescribeStyles, row Row) string

RenderRow formats a single row (without a trailing newline) using the styles. It is shared by the static renderer and the interactive viewer.

func StateColor

func StateColor(state string) color.Color

StateColor maps a state string to a color: green for healthy, red for error/failed, gray for disabled/pending. Returns nil for anything else.

func Structured

func Structured(w io.Writer, f Format, v any) (bool, error)

Structured writes v as JSON or YAML. Returns (true, err) if it handled the format, or (false, nil) if the caller should render a table itself.

func StyledTable

func StyledTable(w io.Writer, header []string, rows [][]string, cellColor CellColor) error

StyledTable renders a colorized, bordered table when w is a terminal, and a plain tab-separated table otherwise (pipe-safe). cellColor may be nil.

func WriteTable

func WriteTable(w io.Writer, header []string, rows [][]string) error

WriteTable renders rows with a tab-separated header, kubectl style.

Types

type CellColor

type CellColor func(col int, value string) color.Color

CellColor returns a foreground color for a table cell, or nil for the default.

func StateCells added in v0.4.0

func StateCells(cols ...int) CellColor

StateCells builds a CellColor that colors every listed column by StateColor. Use it when a table has more than one state-like column (severity and status, say), which StatusCells cannot express.

func StatusCells

func StatusCells(stateCol int, boolCols ...int) CellColor

StatusCells builds a CellColor that colors a state column (pass -1 to skip) and any number of boolean columns. Keeps callers free of lipgloss.

type DescribeStyles

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

DescribeStyles holds the lipgloss styles for a describe rendering.

func NewStyles

func NewStyles() DescribeStyles

NewStyles exposes describe styles for the interactive viewer, which always targets a real terminal.

type Format

type Format string

Format is a supported -o/--output value.

const (
	Table Format = "table"
	Wide  Format = "wide"
	JSON  Format = "json"
	YAML  Format = "yaml"
	Name  Format = "name"
)

Supported output formats.

func Parse

func Parse(s string) (Format, error)

Parse validates a user-supplied output value.

type Kind

type Kind int

Kind classifies a described value for type-aware coloring.

const (
	KindBranch Kind = iota // a nested object/array header (no scalar value)
	KindString
	KindNumber
	KindBool
	KindNull
)

Value kinds surfaced by the describe flattener.

type Row

type Row struct {
	Depth  int
	Key    string
	Value  string
	Kind   Kind
	Header bool // top-level section header (an object/array), rendered uppercase
	Spacer bool // a blank separator line
}

Row is one flattened line of a described object.

func FlattenObject

func FlattenObject(m map[string]any) []Row

FlattenObject turns a decoded JSON object into an ordered, depth-tagged list of rows: top-level scalars first (a summary block), then each nested object or array as its own section. Suitable for both the static renderer and the viewer.

Jump to

Keyboard shortcuts

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