printer

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 12 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 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Color

func Color(w io.Writer, noColor bool) bool

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.

func Formats

func Formats() []string

Formats lists the accepted values, for help and completion.

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

func (d *Doc) Body(markdown string) *Doc

Body adds a block of markdown to the current section — an agent report, a summary paragraph.

func (*Doc) Field

func (d *Doc) Field(key, value string) *Doc

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.

func (*Doc) Fieldf

func (d *Doc) Fieldf(key, format string, args ...any) *Doc

Fieldf adds a formatted field.

func (*Doc) Render

func (d *Doc) Render() error

Render writes the document.

func (*Doc) Section

func (d *Doc) Section(title string) *Doc

Section starts a new section. Sections with no content are dropped at render time, so a command can declare every section unconditionally and let absent data disappear on its own.

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 ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat resolves the -o value.

func (Format) Structured

func (f Format) Structured() bool

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 New

func New(out io.Writer, format Format, color bool) *Printer

New builds a Printer.

func (*Printer) Color

func (p *Printer) Color() bool

Color reports whether styling is on.

func (*Printer) Doc

func (p *Printer) Doc() *Doc

Doc starts a document.

func (*Printer) Format

func (p *Printer) Format() Format

Format reports the printer's format, for commands that shape their own output (describe, review).

func (*Printer) Markdown

func (p *Printer) Markdown(md string) error

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) Objects

func (p *Printer) Objects(items []any, names []string) error

Objects emits whole objects for the machine-facing formats.

func (*Printer) Out

func (p *Printer) Out() io.Writer

Out exposes the underlying writer for commands writing free-form text.

func (*Printer) Table

func (p *Printer) Table(t *metav1.Table) error

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

func (p *Printer) Tables(groups []Group) error

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.

Jump to

Keyboard shortcuts

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