Documentation
¶
Overview ¶
Package render holds the small text helpers shared by the commands' human output: relative times, aligned tables, the terminal width, colour and plural counts.
Index ¶
- func Age(d time.Duration) string
- func Color(o Opts, state, text string) string
- func Cut(s string, cols int) string
- func DisplayWidth(s string) int
- func Plural(n int, noun string) string
- func RelTime(now, t time.Time) string
- func Table(cols []string, rows [][]string, width int, truncateLast bool) string
- func Width(env func(string) string, isTTY bool) int
- type Opts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Age ¶
Age renders how long something has waited, for a line of text and a JSON value: "10s", "5m", "1h 12m", "2d 3h". It shows the two largest units that are not zero (seconds under a minute, minutes under an hour, hours and minutes under a day, days and hours after), and rounds down. A negative d reads "0s".
func Color ¶
Color wraps text in an ANSI colour for state, but only on a terminal with colour on: o.TTY, not o.NoColor, and NO_COLOR unset or empty. "online" and "ok" are green, "FAIL" and "fail" red, "warn" yellow; any other state is plain.
func Cut ¶
Cut shortens s to at most cols display columns, ending in "…" when it was cut (the ellipsis is within cols). A cols below 1 returns s whole.
func DisplayWidth ¶
DisplayWidth is the number of terminal columns s takes: east-asian wide characters and emoji count 2, combining marks and zero-width characters 0, everything else 1.
func RelTime ¶
RelTime renders t relative to now: "10s ago", "1m ago", "3h ago", "2d ago", and the date (2026-11-19) once t is more than 30 days old. A t at or after now reads "0s ago".
func Table ¶
Table lays out a header and rows in columns separated by two spaces. The header is upper-cased. No line has trailing spaces. When truncateLast is set and a line is wider than width, the last column is cut to fit and ends with "…"; widths are display columns (see DisplayWidth) and cuts fall on rune boundaries. A last column that cannot be shown in at least one rune is left whole. The result has no final newline.