Documentation
¶
Overview ¶
Package printer turns results into output.
This package decides once whether output is for a person or a program. A terminal gets styled tables and rendered markdown. A pipe gets plain text, no escape codes, and aligned columns awk can split. Commands never decide this themselves, so no command can decide 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 has several independent opt-outs 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 no person is reading. TERM=dumb catches terminals that cannot render it.
Types ¶
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc builds the detail views that `describe` and `review` print.
Commands declare structure (a section, a field, a body of markdown), never formatting. The same declarations render as styled terminal output or as markdown depending only on the printer's format, so `patchy review -o markdown` pastes cleanly into an issue without a second code path.
func (*Doc) Body ¶
Body adds a block of markdown, such as an agent report or a summary paragraph, to the current section.
func (*Doc) Field ¶
Field adds a key/value line to the current section. An empty value is skipped, so a dozen "<none>" rows do not bury the fields that have values.
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, as `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, so 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. kubectl applies the same rule, and it is why only `-o wide` shows issue and PR links.