Documentation
¶
Overview ¶
Package output provides rendering utilities for CLI command output.
Index ¶
- Constants
- Variables
- func FormatRelativeTime(rfc3339 string) string
- func LabelWidth(groups ...[]DetailLine) int
- func OrDash(s string) string
- func PageCount(total, pageSize int) int
- func PrintAligned(w io.Writer, isTTY bool, lines []DetailLine, indent string, width int) error
- func PrintDetailLines(w io.Writer, isTTY bool, lines []DetailLine) error
- func PrintHeading(w io.Writer, isTTY bool, text string) error
- func PrintJSON(w io.Writer, v any) error
- func PrintTable(w io.Writer, isTTY bool, headers []string, rows [][]Cell) error
- func PrintYAML(w io.Writer, v any) error
- func RelativeTime(t time.Time) string
- func SingleLine(s string) string
- func Truncate(s string, maxWidth int) string
- type Cell
- func AvailableText(available bool) Cell
- func Blue(s string) Cell
- func Concat(cells ...Cell) Cell
- func Gray(s string) Cell
- func Green(s string) Cell
- func Hyperlink(text, target string) Cell
- func Red(s string) Cell
- func StatusColor(status string) Cell
- func Text(s string) Cell
- func Texts(ss ...string) []Cell
- func Yellow(s string) Cell
- type DetailLine
Constants ¶
const EmptyCell = "-"
EmptyCell is the table placeholder for an absent value.
const MaxMessageLen = 80
MaxMessageLen caps a free-text MESSAGE column on a TTY. Piped output is not truncated.
Variables ¶
var ( HeaderStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(accentColor)).Padding(0, 1) EvenRowStyle = lipgloss.NewStyle().Padding(0, 1).Foreground(lipgloss.BrightWhite) OddRowStyle = lipgloss.NewStyle().Padding(0, 1).Foreground(lipgloss.Color(mutedColor)) BorderStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(accentColor)) LabelStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(mutedColor)).Width(detailLabelWidth) ValueStyle = lipgloss.NewStyle() DimStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(mutedColor)) )
Style definitions shared across all commands.
Functions ¶
func FormatRelativeTime ¶ added in v0.4.0
FormatRelativeTime converts an RFC3339 timestamp to a short relative display. Returns the original string if parsing fails.
func LabelWidth ¶ added in v0.20.0
func LabelWidth(groups ...[]DetailLine) int
LabelWidth returns the display width of the longest label across groups, as PrintAligned measures it, so sibling blocks can share one label column.
func PageCount ¶ added in v0.20.0
PageCount returns the number of pages of pageSize needed to hold total items. The result is at least 1, also for a non-positive pageSize.
func PrintAligned ¶ added in v0.20.0
PrintAligned writes "<indent><label><pad> <value>" per line, each on one row with its control characters visible. The label column is width or LabelWidth(lines), whichever is wider. When isTTY, labels use alignedLabelStyle and a non-zero Styled replaces Value.
func PrintDetailLines ¶ added in v0.20.0
func PrintDetailLines(w io.Writer, isTTY bool, lines []DetailLine) error
PrintDetailLines writes one "<label>: <value>" line per entry, each on one row with its control characters visible. Plain output pads "<label>:" to detailLabelWidth columns. When isTTY, labels use LabelStyle and a non-zero Styled replaces the ValueStyle rendering of Value.
func PrintHeading ¶ added in v0.20.0
PrintHeading writes a section heading: HeaderStyle when isTTY, "<text>:" otherwise.
func PrintJSON ¶
PrintJSON encodes v as indented JSON to w. DEL and the C1 runes U+0080-U+009F are written as \u escapes: the process streams drop them raw.
func PrintTable ¶
PrintTable writes a styled table of the styled forms when isTTY, a plain tabwriter table of the plain forms otherwise. Every header stays on one row with its control characters visible.
func RelativeTime ¶ added in v0.8.0
RelativeTime renders t as a short "Xm ago"/"Xh ago"/"Xd ago" string, or a Jan-Mon date for anything older than a week.
func SingleLine ¶ added in v0.16.0
SingleLine makes s printable and collapses every whitespace run, newlines included, into one space, so a multi-line operator message fits one row.
Types ¶
type Cell ¶ added in v0.20.0
type Cell struct {
// contains filtered or unexported fields
}
Cell is a table cell or detail value in two forms, plain and styled, each printable on one row. Only this package builds a styled form.
func AvailableText ¶
AvailableText is "Yes" or "No" in place of true/false; the styled form is green or red.
func Hyperlink ¶ added in v0.4.0
Hyperlink is text, printable on one row, styled as an OSC 8 link to target when termseq.Link accepts the target, which it percent-encodes. Otherwise both forms are the text alone. Empty text is the zero Cell.
func StatusColor ¶
StatusColor is the KubeRocketCI CRD status as a Cell, styled by value:
- "created" green
- "in_progress" yellow
- "failed" red
Any other value is unstyled in both forms.
func Text ¶ added in v0.20.0
Text is s, printable on one row, unstyled in both forms. Text("") is the zero Cell.
type DetailLine ¶
DetailLine holds one label-value pair for resource detail rendering. In a terminal, the styled form of a non-zero Styled is shown instead of Value. Only the styled form of Styled is used; plain output prints Value.