output

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 8 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.

Functions

func AvailableText

func AvailableText(available bool) string

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

func GreenText

func GreenText(s string) string

GreenText returns s rendered in green.

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 rounded borders and styled rows.

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