output

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package output owns serialization and terminal presentation of prepared values.

Index

Constants

View Source
const (
	GlyphPass    = "✓"
	GlyphFail    = "✗"
	GlyphSkip    = "‒"
	GlyphBlocked = "⊘"
	GlyphWarn    = "⚠"
)

Status glyphs shared across surfaces: a passing/success mark, a failure mark, and a skipped/secondary dash. Pair with Pass/Fail/Dim for color.

Variables

This section is empty.

Functions

func Bold

func Bold(s string, color bool) string

Bold renders s bold when color is on, else verbatim.

func ColorEnabled

func ColorEnabled(w io.Writer) bool

ColorEnabled reports whether w should receive ANSI styling. colorprofile.Detect honors NO_COLOR / CLICOLOR(_FORCE) and TTY-ness; anything at or below Ascii (a pipe, a redirect, a dumb terminal) renders plain.

func Cyan

func Cyan(s string, color bool) string

Cyan renders s cyan when color is on, else verbatim.

func Dim

func Dim(s string, color bool) string

Dim renders s faint when color is on, else verbatim.

func Document

func Document(blocks ...string) string

Document assembles a footer from section blocks: a leading blank line parts it from preceding output, a single blank line separates each non-empty block, and it ends with a newline. Returns "" when every block is empty, so the caller writes nothing. Blocks carry no blank lines of their own — spacing lives here, in one place, so there's no per-section newline bookkeeping to drift. Shared by the build/diff failure report and the `flate test` roster.

func Elapsed

func Elapsed(d time.Duration) string

Elapsed renders a duration compactly for live and summary timing: tenths of a second under a minute, m+ss above it.

func Fail

func Fail(s string, color bool) string

Fail renders s as a failure (red) when color is on, else verbatim.

func LineSubjects

func LineSubjects(changes []LineChange, format Format) []manifest.NamedResource

LineSubjects inventories only the resource and producer labels this format prints.

func MessageTail

func MessageTail(message string, paint func(string, bool) string, color bool) string

MessageTail trims blank lines and paints each continuation line separately.

func NameLines

func NameLines(changes []LineChange, names Names)

NameLines binds the invocation's resolved subjects to its line changes.

func Pass

func Pass(s string, color bool) string

Pass renders s as a success (green) when color is on, else verbatim.

func Truncate

func Truncate(s string, width int) string

Truncate shortens s to width visible columns, appending an ellipsis on overflow. It is ANSI- and wide-rune-aware (escape sequences and CJK width are counted correctly), so a styled line truncates by what's actually shown.

func Verdict

func Verdict(color bool, glyph string, elapsed time.Duration, counts ...Count) string

Verdict renders a one-line run summary from an already painted glyph, counts joined by " · ", and a dim elapsed clock (omitted when zero). The first count always shows (even at zero, e.g. "0 passed"); later counts show only when non-zero. Returns "" when given no counts. Shared by the build/diff failure report and the `flate test` roster so both speak one verdict grammar.

func Warn

func Warn(s string, color bool) string

Warn renders s as an advisory (yellow) when color is on, else verbatim.

Types

type Case

type Case struct {
	ID      manifest.NamedResource
	Outcome Outcome
	Reason  string
}

Case is one resource result.

type Column

type Column struct {
	Header string
	Key    string
}

Column describes a single table column.

type Count

type Count struct {
	N     int
	Label string
	Paint func(string, bool) string
}

Count is one labeled tally in a Verdict line: N items, a noun, and the paint that colors "<N> <Label>" (e.g. Fail for "failed").

type DiffGroup

type DiffGroup struct {
	Cluster        string
	Added, Removed bool
	Body           []byte
}

DiffGroup holds one cluster's prepared diff and presence on each side.

type DocumentGroup

type DocumentGroup struct {
	Cluster   string           `json:"cluster"`
	Documents []map[string]any `json:"documents"`
}

DocumentGroup holds one cluster's prepared documents.

type Encoder

type Encoder struct {
	Writer io.Writer
	Format Format
	Color  bool
}

Encoder writes prepared values to one destination with resolved format and color.

func (Encoder) DiffGroups

func (e Encoder) DiffGroups(groups []DiffGroup) error

DiffGroups writes canonical per-cluster JSON changes and suppressions.

func (Encoder) DocumentGroups

func (e Encoder) DocumentGroups(groups []DocumentGroup) error

DocumentGroups writes cluster framing around multiple document groups.

func (Encoder) Documents

func (e Encoder) Documents(docs []map[string]any) error

Documents writes a JSON array or a multi-document YAML stream.

func (Encoder) Errors

func (e Encoder) Errors(err error) error

Errors prints the non-resource remainder returned by selection.

func (Encoder) ImageGroups

func (e Encoder) ImageGroups(groups []ImageGroup) error

ImageGroups writes cluster framing around multiple image groups.

func (Encoder) Images

func (e Encoder) Images(images []string) error

Images writes the prepared image list in its supplied order.

func (Encoder) JSON

func (e Encoder) JSON(value any) error

JSON emits a 2-space-indented JSON document.

func (Encoder) Lines

func (e Encoder) Lines(changes []LineChange) error

Lines consumes prepared resource differences once in unified or HTML format.

func (Encoder) Names

func (e Encoder) Names(values iter.Seq[string]) error

Names writes prepared names in their supplied order.

func (Encoder) Native

func (e Encoder) Native(report *dyff.Report) error

Native writes a prepared dyff report.

func (Encoder) Report

func (e Encoder) Report(r *Report, results Encoder) error

Report writes results, warnings, cluster summaries and the test invocation total in order.

func (Encoder) Tables

func (e Encoder) Tables(sections []Table) error

Tables writes ordered table sections with one blank line between them.

func (Encoder) YAML

func (e Encoder) YAML(value any) error

YAML emits a single document.

type Format

type Format string

Format is the discriminator selected via -o on the CLI.

const (
	FormatTable  Format = "table"
	FormatYAML   Format = "yaml"
	FormatJSON   Format = "json"
	FormatName   Format = "name"
	FormatHuman  Format = "human"
	FormatGitHub Format = "github"
	FormatDiff   Format = "diff"
	FormatHTML   Format = "html"
	FormatBrief  Format = "brief"
	FormatGitLab Format = "gitlab"
	FormatGitea  Format = "gitea"
)

Format values understood by the -o flag.

func DiffFormats

func DiffFormats() []Format

DiffFormats lists accepted diff formats in help order, with the default first. Callers must not modify this list.

type ImageGroup

type ImageGroup struct {
	Cluster string   `json:"cluster"`
	Images  []string `json:"images"`
	Added   bool     `json:"added,omitempty"`
	Removed bool     `json:"removed,omitempty"`
	Names   []string `json:"-"`
}

ImageGroup holds one cluster's prepared images.

type LineChange

type LineChange struct {
	Resource, Parent Subject
	ParentPath       string
	From, To         string
	Status, Label    string
}

LineChange carries canonical diff values and resolved presentation labels.

func PrepareLines

func PrepareLines(prepared diffprep.Prepared) ([]LineChange, error)

PrepareLines collects serialization errors before any report is written.

type Missing

type Missing struct {
	ID         manifest.NamedResource
	RequiredBy []manifest.NamedResource
}

Missing is a dependency that never rendered (absent from the store) yet was required by one or more resources — the other kind of root cause. RequiredBy lists the resources blocked on it (sorted).

type Model

type Model struct {
	// Subjects overrides group context; an empty non-nil map retains ordinary snapshot identities.
	Subjects map[manifest.NamedResource]manifest.DiagnosticIdentity
	Names    *Names
	Context  string
	Primary  []Primary
	Missing  []Missing
	// Blocked is the count of distinct derived (cascaded) failures. It is the
	// verdict's "N blocked" figure — distinct resources, not the sum of the
	// per-root Blocks/RequiredBy lists, which can overlap when one resource
	// traces to more than one root (e.g. a failed parent AND a missing dep).
	Blocked int
}

Model is the partitioned, deterministic view the renderer consumes.

type Names

type Names struct {
	Prefix   string
	Subjects map[manifest.NamedResource]Subject
}

Names contains the prepared labels for one retained cluster.

func PrepareNames

func PrepareNames(
	clusters []string,
	inventory [][]manifest.NamedResource,
	subjects []map[manifest.NamedResource]manifest.DiagnosticIdentity,
) []Names

PrepareNames resolves cluster qualifiers and kind collisions across printed subjects.

type Outcome

type Outcome int

Outcome enumerates the per-resource result.

const (
	OutcomePassed Outcome = iota
	OutcomeSkipped
	OutcomeFailed
	// OutcomeBlocked means a failed or missing dependency prevented the body from running.
	OutcomeBlocked
)

Possible Outcome values.

type Primary

type Primary struct {
	ID     manifest.NamedResource
	Msg    string
	Blocks []manifest.NamedResource
}

Primary is a resource that failed on its own — a real render/template/build error. Blocks lists the resources whose failure cascaded from it (sorted).

type Report

type Report struct {
	Groups   []ReportGroup
	Warnings []Warning
	Test     bool
	Elapsed  time.Duration
	Error    error
}

Report coordinates the invocation's results, warnings and summaries.

func (*Report) Prepare

func (r *Report) Prepare(extra [][]manifest.NamedResource) []Names

Prepare samples continuations and resolves every printed subject before writing.

type ReportGroup

type ReportGroup struct {
	Cluster  string
	Subjects map[manifest.NamedResource]manifest.DiagnosticIdentity
	Models   []Model
	Test     *TestReport
	Names    Names
}

ReportGroup contains one cluster's diagnostics and optional test roster.

type Subject

type Subject struct {
	ID         manifest.NamedResource
	Kind, Name string
}

Subject keeps canonical identity separate from its resolved human labels.

type Table

type Table struct {
	Columns []Column
	Rows    []map[string]string
}

Table holds final columns and rows for one prepared table section.

type TestReport

type TestReport struct {
	Cases   []Case
	Passed  int
	Skipped int
	Failed  int
	// Blocked follows the roster in its supplied order, with prepared dependency reasons.
	Blocked []Case
	Matched int
}

TestReport is the aggregate outcome.

func (*TestReport) AnyFailed

func (r *TestReport) AnyFailed() bool

AnyFailed includes blocked-only runs, even without a primary failure in scope.

type Warning

type Warning struct {
	Warning manifest.Warning
	// Group is the cluster index; negative values denote invocation-wide notices.
	Group   int
	Context string
	Subject Subject
	// contains filtered or unexported fields
}

Warning retains the producer payload and its prepared display context.

Jump to

Keyboard shortcuts

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