Documentation
¶
Overview ¶
Package printer turns results into output.
One decision is made once, here, and everything else follows from it: is this output for a person or for a program? A terminal gets styled tables and rendered markdown; a pipe gets plain text, no escape codes, aligned columns awk can split. Commands never ask that question themselves, so no command can answer it differently.
The styled and plain paths lay columns out identically — only styling differs — so a screenshot and a pasted pipe show the same shape. Two renderers exist because ANSI escapes break byte-counting alignment: text/tabwriter is correct when there are no escapes, lipgloss is correct when there are.
Index ¶
- func Color(w io.Writer, noColor bool) bool
- func Formats() []string
- type Doc
- type Format
- type Group
- type Printer
- func (p *Printer) Color() bool
- func (p *Printer) Doc() *Doc
- func (p *Printer) Format() Format
- func (p *Printer) Markdown(md string) error
- func (p *Printer) Objects(items []any, names []string) error
- func (p *Printer) Out() io.Writer
- func (p *Printer) Table(t *metav1.Table) error
- func (p *Printer) Tables(groups []Group) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Color ¶
Color reports whether output to w should be styled.
Styling is opt-out in three independent ways because each covers a case the others miss: --no-color is the explicit ask, NO_COLOR is the cross-tool convention, and a non-terminal writer means nobody is reading this with their eyes. TERM=dumb catches terminals that cannot render it.
Types ¶
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc builds the detail views — what `describe` and `review` print.
Commands declare structure (a section, a field, a body of markdown) and never formatting. The same declarations render as styled terminal output or as markdown depending only on the printer's format, which is why `patchy review -o markdown` pastes cleanly into an issue without a second code path.
func (*Doc) Body ¶
Body adds a block of markdown to the current section — an agent report, a summary paragraph.
func (*Doc) Field ¶
Field adds a key/value line to the current section. An empty value is skipped: a detail view listing a dozen "<none>" rows buries the handful of fields that actually say something.
type Format ¶
type Format string
Format is an output shape.
const ( // FormatTable is the default: the server-rendered print columns. FormatTable Format = "table" // FormatWide adds the CRD's priority>0 columns. FormatWide Format = "wide" // FormatJSON emits the objects verbatim. FormatJSON Format = "json" // FormatYAML emits the objects verbatim. FormatYAML Format = "yaml" // FormatName emits `<resource>.<group>/<name>` lines, for xargs. FormatName Format = "name" // FormatMarkdown emits markdown — a table for lists, prose for reports. // This is the paste-into-a-ticket format, so it is never styled. FormatMarkdown Format = "markdown" )
The output formats. table and wide differ only in whether the CRD's lower-priority print columns are included.
func (Format) Structured ¶
Structured reports whether the format is machine-facing, in which case commands emit whole objects rather than a human summary.
type Group ¶ added in v0.7.1
type Group struct {
// Title heads the table.
Title string
// Table is the server-rendered table for that kind.
Table *metav1.Table
}
Group is one titled table in a multi-kind listing — what `get all` prints.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer writes command results in one format.
func (*Printer) Format ¶
Format reports the printer's format, for commands that shape their own output (describe, review).
func (*Printer) Markdown ¶
Markdown writes a markdown document: rendered for a terminal, verbatim otherwise. "Otherwise" covers both a pipe and -o markdown, which is the point — the bytes a user pastes into an issue are the bytes the agent wrote.
func (*Printer) Table ¶
Table renders a server-rendered table. Columns the CRD marked priority>0 are held back unless the format is wide — the same rule kubectl applies, and the reason `-o wide` shows issue and PR links.
func (*Printer) Tables ¶ added in v0.7.1
Tables renders several titled tables as one listing, separated by a blank line. Groups with nothing in them are dropped, so a caller can hand over every kind and let the empty ones disappear — a namespace with two findings and no forges should not print five empty headings.