Documentation
¶
Overview ¶
Package magetui renders mage builds as a live, tree-shaped progress display in the style of docker buildx: spinners and elapsed timers on running steps, scrolling output tails, completed subtrees committed to terminal scrollback, and full output replay for failed steps only.
magetui is a renderer, not a build system: Deps reproduces the mg.Deps contract exactly (parallel execution, once-per-target dedup, all siblings run to completion, errors aggregated) while observing the run. Targets opt in explicitly by wrapping their body in Target; unwrapped targets remain plain mage targets.
See DESIGN.md in the repository for the full design.
Index ¶
- Variables
- func Deps(ctx context.Context, deps ...any)
- func Output(ctx context.Context, cmd string, args ...string) (string, error)
- func Printf(ctx context.Context, format string, a ...any)
- func Run(ctx context.Context, cmd string, args ...string) error
- func RunWith(ctx context.Context, env map[string]string, cmd string, args ...string) error
- func Status(ctx context.Context, text string)
- func Step(ctx context.Context, name string, fn func(context.Context) error, ...) error
- func Target(ctx context.Context, fn func(context.Context) error, opts ...TargetOption) error
- type Dep
- type ProgressMode
- type Runnable
- type StepOption
- type TargetOption
- type Theme
Constants ¶
This section is empty.
Variables ¶
var ( // ThemeColor is the default: full Unicode glyphs, icons kept, and a // basic-ANSI palette — the terminal's own colors follow the user's // light/dark scheme by construction. ThemeColor = Theme(render.ThemeColor) // ThemeGreyscale is intensity without hue: full glyphs and icons // over greys and weight. ThemeGreyscale = Theme(render.ThemeGreyscale) // ThemeMono uses no color at all; Unicode glyphs and icons stay. // Answers "I hate colors", not "my terminal is from 1978". ThemeMono = Theme(render.ThemeMono) // ThemeASCII is the pure-ASCII repertoire for glyph-poor terminals: // OK/XX/!! markers, -\|/ spinner, icons dropped. It keeps the color // palette — a linux console still has the basic 8. ThemeASCII = Theme(render.ThemeASCII) )
The embedded themes are design intents, not capability-matrix cells (DESIGN.md §5). The conversions double as the compile-time check that this struct and its internal twin stay field-for-field identical.
Functions ¶
func Deps ¶
Deps runs the dependencies with mg.Deps semantics: in parallel, each exactly once per Target however many dependents request it, all siblings run to completion when some fail, errors aggregated in argument order. Accepted dep types mirror mage — func(), func() error, func(context.Context), func(context.Context) error — plus F values and any Runnable. On failure Deps panics the aggregate up the step tree the way mg.Deps does; the enclosing step records it and Target returns it. An invalid dep type panics too: that is a magefile bug, and it renders as one.
func Output ¶
Output is Run with stdout captured and returned to the caller (trailing newline trimmed — sh.Output's contract) instead of recorded; stderr still goes to the step's tail.
func Printf ¶
Printf appends a formatted log line to the current step's scrolling tail — the replacement for stray fmt.Printf in a target body. Multi-line text is recorded line by line; a trailing newline is implied.
func Run ¶
Run executes cmd attributed to the current step: the command line and both output streams land in the step's tail, tagged by origin (DESIGN.md §4.3). stdin is the magefile process's own. $VAR references in cmd and args expand from the process environment — sh.Run's contract.
func RunWith ¶
RunWith is Run with env overlaid on the process environment; $VAR expansion consults env first — sh.RunWith's contract.
func Status ¶
Status replaces the transient status text on the step's own line — the buildx transfer-counter feel. Presentation only: not recorded in the output buffer, absent from the failure replay.
func Step ¶
func Step(ctx context.Context, name string, fn func(context.Context) error, opts ...StepOption) error
Step runs fn as an ad-hoc named sub-step of the current step. Unlike Deps, steps are never deduped: every call runs. The error comes back to the caller — whether it fails the enclosing target is the caller's decision.
func Target ¶
Target is the lifecycle boundary: it boots the renderer, establishes the root step — named after the calling target — in the context, runs fn, and on exit replays the captured output of failed steps (DESIGN.md §2). The error comes back untouched, so mage's exit-code machinery (including mg.Fatal and subprocess exit statuses) behaves exactly as without magetui. Targets that don't wrap stay plain mage targets.
The one shaped error is magetui's own: when the run is interrupted — mage cancels the context on ^C, or magetui's SIGTERM watcher fires — the aggregate comes back carrying the conventional 128+signal exit status (130 or 143), which mage's machinery honors (DESIGN.md §6).
A Target called inside another Target — a library target wrapping defensively, run as somebody's dependency — boots nothing: it becomes an ordinary step of the outer run, options ignored, error untouched.
Types ¶
type Dep ¶
type Dep struct {
// contains filtered or unexported fields
}
Dep is a dependency decorated by F. It implements Runnable (and thereby mg.Fn).
func F ¶
func F(target any, opts ...StepOption) Dep
F attaches step metadata to a dependency, mirroring the mg.F idiom:
magetui.Deps(ctx,
magetui.F(Build, magetui.Icon("🔨")),
Lint, // bare functions still fine
)
F panics if target is not one of the accepted function shapes — a malformed magefile, not a build failure. Decoration never changes identity: a target decorated at one callsite and bare at another is still one step, and the first registration's decoration wins.
type ProgressMode ¶
type ProgressMode int
ProgressMode selects the renderer family. ProgressAuto picks TTY when the output is a terminal and Plain otherwise (DESIGN.md §2). The MAGETUI_PROGRESS environment variable (auto|tty|plain) overrides whatever the code asked for; unrecognized values are ignored.
const ( ProgressAuto ProgressMode = iota ProgressTTY ProgressPlain )
type Runnable ¶
Runnable is the structural shape of a decorated dependency — the same method set as mage's mg.Fn, so the two libraries' decorated deps are mutually acceptable: Deps runs mg.F values, mg.CtxDeps runs F values. Runnable deps dedup on ID.
type StepOption ¶
type StepOption func(*stepOptions)
StepOption decorates a step created by F or Step.
func Icon ¶
func Icon(icon string) StepOption
Icon sets a decorative glyph that rides the step through all renderers. Decoration only — never identity or alignment (DESIGN.md §2).
type TargetOption ¶
type TargetOption func(*targetOptions)
TargetOption configures one Target lifecycle.
func WithOutput ¶
func WithOutput(w io.Writer) TargetOption
WithOutput redirects rendering away from os.Stdout. Auto mode treats a writer that is not a terminal file as not a TTY.
func WithProgressMode ¶
func WithProgressMode(m ProgressMode) TargetOption
WithProgressMode selects the renderer explicitly instead of auto-detecting. MAGETUI_PROGRESS still wins: the person running the build outranks the person who wrote it.
func WithTheme ¶
func WithTheme(t Theme) TargetOption
WithTheme selects the theme for one Target lifecycle. MAGETUI_THEME still wins: the person running the build outranks the person who wrote it.
type Theme ¶
type Theme struct {
// Glyphs.
Spinner []string // animation frames for running steps
Start string // plain mode: started and status lines
OK, Fail, Panic, Interrupted string // final outcome glyphs
GutterOut, GutterErr string // output-line origin markers (stdout, stderr)
GutterCmd string // the command echo
StackGutter string // the trimmed panic-stack block
PathSep string // between step names in paths
Ellipsis string // truncation and elision marker
Separator string // the failure replay's horizontal rule
Dash string // cause separator on committed step lines
Icons bool // render step icons; glyph-poor themes drop them
// Palette.
Name, Duration, Status lipgloss.Style
TailText, TailErr, TailCmd lipgloss.Style
Path lipgloss.Style
SpinnerStyle, OKStyle, FailureStyle, PanicStyle, InterruptedStyle lipgloss.Style
StackStyle lipgloss.Style
}
Theme carries every glyph and style magetui renders, in two flat groups: glyphs (strings, not runes — multi-codepoint glyphs and ligature pairs like "=>" must work) and a lipgloss palette. Selected per Target via WithTheme; the MAGETUI_THEME environment variable (color|greyscale|mono|ascii) overrides whatever the code asked for.
Lifecycle glyphs within one theme should share one display width — the embedded themes do — for the grid's sake; the plain grid and the live tree pad the glyph column to the widest one either way, so a narrower spinner (ASCII's -\|/) is fine. Color capability is not a theme concern: the palette degrades automatically underneath every theme (truecolor → 256 → 16 → none; NO_COLOR forces the bottom), so "ASCII without color" is ThemeASCII plus NO_COLOR, by composition.
Zero-value fields render as empty glyphs and unstyled text; an empty Spinner falls back to the default frames. Plain mode's origin gutters (`$`, `|`, `!`) are deliberately not themed — `grep '^!'` finding all stderr is a contract — while GutterOut/GutterErr style the TUI tail and the failure replay.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
engine
Package engine owns goroutines and the step registry, and reproduces the mg.Deps contract: parallel execution, once-per-target dedup, all siblings run to completion, errors aggregated.
|
Package engine owns goroutines and the step registry, and reproduces the mg.Deps contract: parallel execution, once-per-target dedup, all siblings run to completion, errors aggregated. |
|
events
Package events defines the typed event stream between the execution engine and the renderers.
|
Package events defines the typed event stream between the execution engine and the renderers. |
|
render
Package render hosts the consumers of the typed event stream (DESIGN.md §3.3): the plain renderer, the TUI layout core and its bubbletea adapter, the OSC 9;4 progress emitter, the shared failure replay, and the themes that style them all.
|
Package render hosts the consumers of the typed event stream (DESIGN.md §3.3): the plain renderer, the TUI layout core and its bubbletea adapter, the OSC 9;4 progress emitter, the shared failure replay, and the themes that style them all. |
