Documentation
¶
Overview ¶
Package render turns a stream of record structs into one of the output formats the kit CLI supports: table, markdown, json, jsonl, csv, tsv, url, raw, and a Go text/template. It works off struct reflection and the `table:` and `json:` tags, so any record type renders without per-type code. It holds no domain knowledge and is reusable on its own.
The table and markdown formats are drawn with lipgloss. table is a rounded-border, color-aware grid meant for a terminal; markdown is a GitHub-flavored pipe table meant for pasting into docs, issues, and READMEs. Both buffer their rows and draw once on Flush so every column sizes to its widest cell.
The list format is the readable alternative to a grid: each record becomes a short section — a heading drawn from the first column, then the rest as a "- **key**: value" bullet list — and records stream as they arrive rather than buffering, so a slow command stays responsive. On a terminal (color on) the markdown markers give way to ANSI styling for a clean detail view; piped (color off) it emits literal GitHub-flavored markdown.
Tag grammar (on a struct field):
table:"name" include in the table/csv view under column "name" table:"name,truncate" truncate long values to the terminal width table:"name,time" format a time.Time as 2006-01-02 15:04 table:"name,url" mark the canonical URL column (used by the url format) table:"-" never show in table/csv (still present in json) (no table tag) fall back to the json tag name
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
Format Format // the encoding; Auto resolves to Table on a TTY else JSONL
IsTTY bool // whether the writer is an interactive terminal (for Auto)
Color bool // emit ANSI color (table/list accents, JSON highlighting); kit resolves --color
Fields []string // projection: restrict/reorder columns by name
NoHeader bool // omit the header row in table/csv/markdown, and the heading in list
Template string // when set, format becomes Template
Width int // truncation width for `truncate` columns (0 = no limit)
Writer io.Writer // destination
}
Options configure a Renderer.
type Record ¶
Record is a row a command has already projected: an explicit ordered column set (Cols/Vals) for the table, csv, tsv, and url formats, plus the original Value rendered by json, jsonl, raw, and template. A command emits a Record when its table columns differ from its JSON shape, or when the row comes from a dynamic map that struct reflection cannot plan. Emit handles it like any record; when Value is nil it falls back to a map of the columns.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer renders records incrementally; one instance handles a whole run so streaming formats write as records arrive. The grid formats (table, markdown) instead buffer their rows and draw once on Flush.
func (*Renderer) Emit ¶
Emit renders one record. A record is either a struct (rendered by reflection and its `table:`/`json:` tags) or a Record with explicit columns.