output

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 13 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 output provides rendering utilities for CLI command output.

Index

Constants

View Source
const EmptyCell = "-"

EmptyCell is the table placeholder for an absent value.

View Source
const MaxMessageLen = 80

MaxMessageLen caps a free-text MESSAGE column on a TTY. Piped output is not truncated.

Variables

View Source
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

func FormatRelativeTime(rfc3339 string) string

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 OrDash added in v0.15.0

func OrDash(s string) string

OrDash returns s, or EmptyCell when s is empty.

func PageCount added in v0.20.0

func PageCount(total, pageSize int) int

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

func PrintAligned(w io.Writer, isTTY bool, lines []DetailLine, indent string, width int) error

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

func PrintHeading(w io.Writer, isTTY bool, text string) error

PrintHeading writes a section heading: HeaderStyle when isTTY, "<text>:" otherwise.

func PrintJSON

func PrintJSON(w io.Writer, v any) error

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

func PrintTable(w io.Writer, isTTY bool, headers []string, rows [][]Cell) error

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 PrintYAML added in v0.14.0

func PrintYAML(w io.Writer, v any) error

func RelativeTime added in v0.8.0

func RelativeTime(t time.Time) string

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

func SingleLine(s string) string

SingleLine makes s printable and collapses every whitespace run, newlines included, into one space, so a multi-line operator message fits one row.

func Truncate added in v0.4.0

func Truncate(s string, maxWidth int) string

Truncate shortens s to maxWidth characters, appending "..." if truncated. Returns s unchanged if it fits within maxWidth or maxWidth is 0 (no limit).

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

func AvailableText(available bool) Cell

AvailableText is "Yes" or "No" in place of true/false; the styled form is green or red.

func Blue added in v0.20.0

func Blue(s string) Cell

Blue is s, printable on one row, styled blue.

func Concat added in v0.20.0

func Concat(cells ...Cell) Cell

Concat joins cells form by form.

func Gray added in v0.20.0

func Gray(s string) Cell

Gray is s, printable on one row, styled gray.

func Green added in v0.20.0

func Green(s string) Cell

Green is s, printable on one row, styled green.

func Hyperlink(text, target string) Cell

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 Red added in v0.20.0

func Red(s string) Cell

Red is s, printable on one row, styled red.

func StatusColor

func StatusColor(status string) Cell

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

func Text(s string) Cell

Text is s, printable on one row, unstyled in both forms. Text("") is the zero Cell.

func Texts added in v0.20.0

func Texts(ss ...string) []Cell

Texts is Text applied to each of ss.

func Yellow added in v0.20.0

func Yellow(s string) Cell

Yellow is s, printable on one row, styled yellow.

func (Cell) IsZero added in v0.20.0

func (c Cell) IsZero() bool

IsZero reports whether c is the zero Cell.

func (Cell) Render added in v0.20.0

func (c Cell) Render(isTTY bool) string

Render returns the styled form when isTTY, the plain form otherwise.

type DetailLine

type DetailLine struct {
	Label  string
	Value  string
	Styled Cell
}

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.

Jump to

Keyboard shortcuts

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