render

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package render turns a declarative plan into terminal output. It is separate from the reconciler so the engine has no opinion about presentation, and so the plan's public surface is the only thing a formatter can reach.

The output has two phases with the same table shape: a preview of what will happen, and — once approved — a live account of what did. The preview is one line per resource so it can be taken in at a glance, and expands in place to show the field-by-field detail on request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayPath

func DisplayPath(p string) string

DisplayPath shows a path relative to the working directory when it is beneath it, which is nearly always and much shorter.

Types

type OriginSummary

type OriginSummary struct {
	Credentials  string // "profile <name>", or how else the run authenticates
	Host         string
	Organization string // display form: name and/or id
	Workspace    string
}

OriginSummary is the origin a first apply will create its resources in, in words: how the run authenticates and the host, organization and workspace that reaches.

type Renderer

type Renderer struct {
	// Out receives everything the renderer prints.
	Out io.Writer
	// Color enables ANSI styling, and with it the escapes that hyperlinks (Link)
	// and in-place redraws (Rewind) rely on.
	Color bool
	// Verbose shows unchanged resources, full field values and whole prose
	// diffs rather than the edited stretch.
	Verbose bool
	// Expanded prints each resource's field-level detail beneath its row.
	Expanded bool
	// Viewport, when set, wraps long values to the terminal's width and lets
	// the preview be redrawn in place: see Rewind.
	Viewport Viewport
	// Link, when set, returns a URL for a resource ID (or ""), and IDs are
	// printed as terminal hyperlinks to it. Only honoured with Color, since a
	// terminal that takes no colour will not take the escape either.
	Link func(kind core.Kind, id string) string
	// contains filtered or unexported fields
}

Renderer writes everything `apply` shows a person: the first-run notice, the untracked-resource offer, the plan and its prompt, then the apply as it runs. Out is required; the other fields are optional.

func (*Renderer) Applied

func (r *Renderer) Applied(applied core.Applied)

Applied prints one resource's outcome as it lands. It has the signature of core.Applier.Report.

func (*Renderer) BeginApply

func (r *Renderer) BeginApply(plan *core.Plan)

BeginApply opens the second phase: its heading, noting the lockfile path, and the table's column header.

func (*Renderer) Confirm

func (r *Renderer) Confirm(in io.Reader, question string) (bool, error)

Confirm asks a yes/no question, defaulting to yes.

func (*Renderer) FirstRun

func (r *Renderer) FirstRun(lockfilePath string, c OriginSummary)

FirstRun tells the user, before anything is planned, that this directory has no state yet and where its resources are about to be created.

func (*Renderer) HasDetails

func (r *Renderer) HasDetails(plan *core.Plan) bool

HasDetails reports whether expanding would show anything, so a prompt can decide whether to offer it.

func (*Renderer) Prompt

func (r *Renderer) Prompt(hasDetails bool)

Prompt writes the confirmation question, without a newline. When hasDetails is set the reader is offered a third answer that toggles the expanded view.

func (*Renderer) RenderPlan

func (r *Renderer) RenderPlan(plan *core.Plan)

RenderPlan writes the preview phase: header, warnings, one table row per resource — with its detail beneath when Expanded — a summary, and anything blocking the apply. It marks where it began so a prompt can Rewind and draw it again the other way.

func (*Renderer) RenderResult

func (r *Renderer) RenderResult(res *core.Result, lockfilePath string, err error)

RenderResult closes the second phase with what was actually done. err is the apply's error, if it stopped early; the caller still reports it in full.

func (*Renderer) Rewind

func (r *Renderer) Rewind(extra int) bool

Rewind erases everything written since the preview began (RenderPlan marks that point), plus extra rows the renderer did not write itself (an echoed line of input), provided all of it is still on screen. It reports whether it did; when it could not, nothing is touched.

func (*Renderer) Untracked

func (r *Renderer) Untracked(root string, found []core.Found, firstRun bool)

Untracked lists resources found on disk that the lockfile does not track, ahead of asking whether to include them.

type Viewport

type Viewport func() (width, height int)

Viewport reports the terminal's size. The renderer wraps long values to its width, and redraws in place only when everything since the rewind point fits its height. Without one it neither wraps nor redraws.

Jump to

Keyboard shortcuts

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