render

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package render is the human-facing visual system for refresh: a small design language (palette, status tokens, primitives) plus an in-place live-region printer. It is line-oriented CLI output — NOT a TUI (no alternate screen, no input loop). Color is always additive: every status also carries a glyph and a label, so output stays legible with --no-color, when piped, or on a non-UTF-8 terminal.

Machine formats (-o json/yaml/plain) do not go through this package; they stay in runner.EncodeStdout. render only styles the human `table`/detail surfaces, reusing the ANSI-width math in internal/ui.

Index

Constants

This section is empty.

Variables

View Source
var Mocha = Palette{
	Text:    Color{205, 214, 244},
	Subtext: Color{166, 173, 200},
	Dim:     Color{108, 112, 134},
	White:   Color{235, 239, 252},
	Rule:    Color{69, 71, 90},
	Green:   Color{166, 227, 161},
	Yellow:  Color{249, 226, 175},
	Red:     Color{243, 139, 168},
	Teal:    Color{148, 226, 213},
	Blue:    Color{137, 180, 250},
	Mauve:   Color{203, 166, 247},
	Peach:   Color{250, 179, 135},
	Sky:     Color{137, 220, 235},
}

Mocha is the default palette (Catppuccin Mocha) — a real, widely-used terminal theme that downgrades cleanly to 256-color.

Functions

This section is empty.

Types

type Color

type Color struct{ R, G, B uint8 }

Color is a 24-bit RGB color.

type ColorLevel

type ColorLevel int

ColorLevel is the terminal's color capability.

const (
	ColorNone ColorLevel = iota // no ANSI color (NO_COLOR, piped, dumb term)
	Color256                    // 256-color palette
	ColorTrue                   // 24-bit truecolor
)

func DetectLevel

func DetectLevel(w io.Writer) ColorLevel

DetectLevel reports the color capability for w. Honors NO_COLOR, fatih/color's global (set by --no-color), TTY-ness, COLORTERM and TERM.

type LiveRegion

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

LiveRegion repaints a multi-line block in place on a TTY (cursor-up + clear-to-end), and degrades to appended snapshots when output isn't a terminal (or color is off) — so logs and pipes never get escape codes or a flicker of half-frames. It is line-oriented: it never uses the alternate screen buffer, so scrollback is preserved and it stays a CLI, not a TUI.

The frame model is a pure func() []string; this type only paints it, which keeps the rendering testable without a pseudo-terminal.

func (*LiveRegion) Draw

func (lr *LiveRegion) Draw(frame []string)

Draw paints one frame. On a TTY it overwrites the previous frame in place; off a TTY it appends the frame (callers throttle the cadence so logs stay sane).

func (*LiveRegion) Run

func (lr *LiveRegion) Run(ctx context.Context, interval time.Duration, frame func() (lines []string, done bool)) error

Run draws frames every interval until frame reports done==true or ctx is cancelled. The cursor is hidden during a TTY run and always restored.

type Palette

type Palette struct {
	Text, Subtext, Dim, White, Rule                   Color
	Green, Yellow, Red, Teal, Blue, Mauve, Peach, Sky Color
}

Palette is the named color set the design system draws from.

type Status

type Status int

Status is a semantic state with a fixed glyph + color, so meaning is carried by the glyph (not color alone).

const (
	Neutral  Status = iota // •  dim
	Healthy                // ●  green  — active / current / pass
	Warn                   // ▲  yellow — stale / warning
	Fail                   // ✗  red    — failed / blocked
	Progress               // ◷  teal   — updating / in-progress
	Unknown                // ○  dim    — unknown / n-a
)

func StatusFromString

func StatusFromString(s string) Status

StatusFromString maps a free-form AWS/Kubernetes status to a Status using the single classification table in internal/ui (so the vocabulary never drifts).

type Table

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

Table builds an aligned, optionally-colored table that returns its lines (header + rows). Column sizing/alignment reuse the ANSI-width helpers in internal/ui, so colored and glyph cells line up exactly.

func (*Table) Render

func (tb *Table) Render() []string

Render returns the header line followed by one line per row.

func (*Table) Row

func (tb *Table) Row(cells ...string) *Table

Row appends a row. Extra cells are ignored; missing cells render empty.

type Theme

type Theme struct {
	Level   ColorLevel
	Unicode bool
	Pal     Palette
}

Theme renders strings at a given color level and Unicode capability. It is safe to copy; it holds no state.

func Default

func Default(w io.Writer) *Theme

Default detects the color level and Unicode support from w and the environment.

func New

func New(level ColorLevel, unicode bool) *Theme

New builds a Theme with an explicit level/unicode (used in tests for determinism).

func (*Theme) Bar

func (t *Theme) Bar(done, total, width int, c Color) string

Bar renders a block-glyph progress bar of the given width filled to done/total in color c.

func (*Theme) Bold

func (t *Theme) Bold(c Color, s string) string

func (*Theme) Branch

func (t *Theme) Branch(last bool) string

Branch returns the tree connector for a list item ("├─" / "└─" for the last).

func (*Theme) Callout

func (t *Theme) Callout(title string, body []string, width int) []string

Callout renders a titled block bounded by top/bottom rules (no side borders, so it is trivially alignment-safe). width is the rule length.

func (*Theme) Glyph

func (t *Theme) Glyph(s Status) string

Glyph renders just the status glyph, colored.

func (*Theme) KV

func (t *Theme) KV(pairs [][2]string) []string

KV renders aligned key/value detail rows: the keys are dim and padded to a common width, the values are passed through (may already be colored).

func (*Theme) NewLiveRegion

func (t *Theme) NewLiveRegion(w io.Writer) *LiveRegion

NewLiveRegion returns a LiveRegion for w. It repaints in place only when w is a terminal and the theme has color enabled.

func (*Theme) NewTable

func (t *Theme) NewTable(cols ...ui.Column) *Table

NewTable starts a table with the given columns.

func (*Theme) Paint

func (t *Theme) Paint(c Color, s string) string

Paint wraps s in the foreground color for the active level (no-op at ColorNone). Bold is the same with the bold attribute.

func (*Theme) Section

func (t *Theme) Section(title string) string

Section returns a section header line: "▸ TITLE" in the accent color.

func (*Theme) Token

func (t *Theme) Token(s Status, label string) string

Token renders "glyph label" — the glyph colored, the label in the caller's default text color. Pass an empty label for the glyph alone.

func (*Theme) Tokenf

func (t *Theme) Tokenf(s Status, label string) string

Tokenf is Token with the label colored to match the status (used where the whole token should read as one unit, e.g. a verdict).

Jump to

Keyboard shortcuts

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