output

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package output provides rendering utilities for CLI command output.

Index

Constants

View Source
const (
	FormatTable = "table"
	FormatJSON  = "json"
)

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("245"))
	BorderStyle  = lipgloss.NewStyle().Foreground(lipgloss.Color(accentColor))
	LabelStyle   = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("245")).Width(14)
	ValueStyle   = lipgloss.NewStyle()
)

Style definitions shared across all commands.

View Source
var (
	SectionStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(accentColor))
	ReasonLabel  = LabelStyle.Width(12)
	SuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Green)
	FailStyle    = lipgloss.NewStyle().Foreground(lipgloss.Red)
	DimStyle     = lipgloss.NewStyle().Foreground(lipgloss.Color("245"))
)

Pipeline run output styles.

Functions

func AvailableText

func AvailableText(available bool) string

AvailableText returns a colorized "Yes" or "No" instead of true/false.

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 GreenText

func GreenText(s string) string

GreenText returns s rendered in green.

func Hyperlink(text, url string) string

Hyperlink wraps text in an OSC 8 terminal hyperlink sequence. The text is displayed normally but is clickable in supported terminals.

func PipelineStatusColor added in v0.4.0

func PipelineStatusColor(status string) string

func PrintJSON

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

PrintJSON encodes v as indented JSON to w.

func PrintPlainDetailLines

func PrintPlainDetailLines(w io.Writer, lines []DetailLine) error

PrintPlainDetailLines renders detail lines as plain text for piped output.

func PrintStyledDetailLines

func PrintStyledDetailLines(w io.Writer, lines []DetailLine) error

PrintStyledDetailLines renders detail lines with lipgloss styling.

func PrintStyledTable

func PrintStyledTable(w io.Writer, headers []string, rows [][]string) error

PrintStyledTable renders a lipgloss table with colored headers, alternating row colors, and no borders. Uses lipgloss for ANSI-aware column width calculation.

func PrintTable

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

PrintTable renders a plain-text table for piped or non-TTY output.

func RenderDetail

func RenderDetail[T any](ios *iostreams.IOStreams, outputFormat string, data T, r DetailRenderer[T]) error

RenderDetail handles the common format-resolution and output logic for detail commands.

func RenderList

func RenderList[T any](
	ios *iostreams.IOStreams,
	outputFormat string,
	data T,
	toRows func(isTTY bool) (headers []string, rows [][]string),
) error

RenderList handles the common format-resolution and output logic for list commands. toRows receives the isTTY flag so callers can apply color only when rendering to a terminal.

func RenderNoTaskData added in v0.4.0

func RenderNoTaskData(w io.Writer, status string) error

RenderNoTaskData writes a dim status message for --reason when no task data is available.

func RenderReason added in v0.4.0

func RenderReason(w io.Writer, result *portal.PipelineRunListResult) error

RenderReason renders pipeline info + task tree + failure diagnosis using lipgloss.

func RenderRunInfo added in v0.4.0

func RenderRunInfo(w io.Writer, run *portal.PipelineRunInfo) error

RenderRunInfo renders a single pipeline run's info header.

func ResolveFormat

func ResolveFormat(explicit string) string

ResolveFormat returns the explicit format if provided, otherwise defaults to table. Use -o json for JSON output.

func StatusColor

func StatusColor(status string) string

StatusColor returns the status string with color applied based on its value. Recognized values (from KubeRocketCI CRD status field):

  • "created" renders green
  • "in_progress" renders yellow
  • "failed" renders red

Any other value is returned unstyled.

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

func YellowText

func YellowText(s string) string

YellowText returns s rendered in yellow.

Types

type DetailLine

type DetailLine struct {
	Label  string
	Value  string
	Styled string
}

DetailLine holds one label-value pair for resource detail rendering. When Styled is populated, the styled renderer uses it instead of Value.

type DetailRenderer

type DetailRenderer[T any] struct {
	Styled func(io.Writer, T) error
	Plain  func(io.Writer, T) error
}

DetailRenderer defines styled and plain rendering for a resource detail view.

Jump to

Keyboard shortcuts

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