Documentation
¶
Overview ¶
Package output renders API results as kubectl-style tables or as JSON/YAML.
Index ¶
- Variables
- func BoolColor(value string) color.Color
- func IsTerminal(w io.Writer) bool
- func PlainRow(row Row) string
- func PrintSectionHeader(w io.Writer, text string) error
- func RenderDescribe(w io.Writer, title string, rows []Row) error
- func RenderRow(s DescribeStyles, row Row) string
- func StateColor(state string) color.Color
- func Structured(w io.Writer, f Format, v any) (bool, error)
- func StyledTable(w io.Writer, header []string, rows [][]string, cellColor CellColor) error
- func WriteTable(w io.Writer, header []string, rows [][]string) error
- type CellColor
- type DescribeStyles
- type Format
- type Kind
- type Row
Constants ¶
This section is empty.
Variables ¶
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.
var ErrUnsupportedFormat = errors.New("unsupported output format")
ErrUnsupportedFormat is returned by Parse for an unknown output format.
Functions ¶
func IsTerminal ¶ added in v0.2.0
IsTerminal reports whether w is a terminal, so callers can decide between a styled, grouped presentation and a flat, pipe-safe one.
func PlainRow ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
StyledTable renders a colorized, bordered table when w is a terminal, and a plain tab-separated table otherwise (pipe-safe). cellColor may be nil.
Types ¶
type CellColor ¶
CellColor returns a foreground color for a table cell, or nil for the default.
func StateCells ¶ added in v0.4.0
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 ¶
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.
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 ¶
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.