render

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LEVEL_0 = iota
	LEVEL_1
	LEVEL_2
	LEVEL_3
	LEVEL_4
)

Level constants (each level = 2 spaces indentation).

Variables

View Source
var (
	YAMLKeyStyle    = lipgloss.NewStyle().Foreground(theme.SyntaxKey)
	YAMLStringStyle = lipgloss.NewStyle().Foreground(theme.SyntaxString)
	YAMLNumberStyle = lipgloss.NewStyle().Foreground(theme.SyntaxNumber)
	YAMLBoolStyle   = lipgloss.NewStyle().Foreground(theme.SyntaxBool)
	YAMLNullStyle   = lipgloss.NewStyle().Foreground(theme.SyntaxNull)
	YAMLMarkerStyle = lipgloss.NewStyle().Foreground(theme.SyntaxMarker)
)

YAML syntax-highlighting styles (exported).

Functions

func FormatAge

func FormatAge(obj *unstructured.Unstructured) string

FormatAge returns a human-readable age string for an Unstructured object.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration as a human-readable age string (Xs/Xm/Xh/Xd).

func MapOffsets

func MapOffsets(rawText, displayText string, rawOffsets [][]int) [][]int

MapOffsets translates byte-offset pairs from raw (plain-text) space to display (ANSI-colored) space.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder accumulates typed elements and renders them with dynamic per-section alignment.

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new empty Builder.

func (*Builder) AppendAt

func (b *Builder) AppendAt(level int, i *Builder) *Builder

AppendAt appends existing builder's elements at the given indentation level.

func (*Builder) Build

func (b *Builder) Build() Content

Build performs a two-pass render and returns a Content holding (raw, display) output. raw contains no ANSI escape codes; display contains styled output. The invariant ansi.Strip(display) == raw always holds.

func (*Builder) KV

func (b *Builder) KV(level int, key, value string, opts ...KVOption) *Builder

KV appends a key-value element with optional KVOption modifiers.

func (*Builder) KVMulti

func (b *Builder) KVMulti(level int, key string, m map[string]string, opts ...KVOption) *Builder

KVMulti appends a key with a sorted map of key=value pairs. The first value appears on the same line as the key; subsequent values appear on continuation lines aligned to the same column. A nil or empty map renders as "<none>".

func (*Builder) KVStyled

func (b *Builder) KVStyled(level int, kind ValueKind, key, value string) *Builder

KVStyled appends a key-value element with a specific ValueKind for styling.

func (*Builder) RawLine

func (b *Builder) RawLine(level int, text string) *Builder

RawLine appends an unstyled line of text at the given indentation level.

func (*Builder) Section

func (b *Builder) Section(level int, name string) *Builder

Section appends a section header element. It renders as "indent + name + :\n".

type Content

type Content struct {
	Raw     string
	Display string
}

Content holds the raw (plain-text) and display (ANSI-styled) representations of rendered content. The invariant ansi.Strip(c.Display) == c.Raw always holds.

func RenderEvents

func RenderEvents(allEvents []*unstructured.Unstructured, kind, name, namespace string) Content

RenderEvents filters events matching the given resource, sorts newest-first, and returns a kubectl-style "Events:" table section as Content.

func YAML

func YAML(m map[string]any) (Content, error)

YAML renders a map[string]any as syntax-colored YAML. It returns a Content holding the raw (plain) and display (ANSI-colored) text.

func (Content) Append

func (c Content) Append(other Content) Content

Append concatenates other to c and returns a new Content. If either operand is empty, the other is returned unchanged. No separator is inserted because Builder.Build output always ends with '\n'.

type Element

type Element struct {
	// contains filtered or unexported fields
}

Element represents a single renderable item in the describe output.

type KVOption

type KVOption func(*Element)

KVOption is a functional option for KV methods on Builder.

func Unaligned

func Unaligned() KVOption

Unaligned marks the KV element as excluded from per-section alignment computation. The key and value are rendered with a single space separator instead.

func WithKind

func WithKind(k ValueKind) KVOption

WithKind sets the ValueKind for styling the value portion of a KV element.

type ValueKind

type ValueKind int

ValueKind tags a field value for semantic styling.

const (
	ValueDefault ValueKind = iota
	ValueStatusOK
	ValueStatusWarn
	ValueStatusError
	ValueStatusGray
	ValueNumber
)

func ConditionKind

func ConditionKind(status string) ValueKind

ConditionKind maps a condition status string to a ValueKind for styling.

func StatusKind

func StatusKind(phase string) ValueKind

StatusKind maps a pod phase string to a ValueKind for styling.

Jump to

Keyboard shortcuts

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