magetui

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

magetui

A docker buildx-style live progress display for mage builds.

magetui rendering a mage build as a live dependency tree

magetui is a Go library — not a CLI, not a mage fork. Import it in your magefile, wrap the targets you care about, and your build renders as a live dependency tree: spinners and elapsed timers on running steps, scrolling output tails, completed subtrees committed to terminal scrollback, and full output replay for failed steps only.

Tabs in captured output expand to eight-column stops before layout, with the same spacing in live tails, plain output, and failure replay.

func All(ctx context.Context) error {
    return magetui.Target(ctx, func(ctx context.Context) error {
        magetui.Deps(ctx,
            magetui.F(Build, magetui.Icon("🔨")),
            magetui.F(Test,  magetui.Icon("🧪")),
        )
        return nil
    })
}

Install

go get github.com/dmotylev/magetui

Go 1.27.2+. Use it inside a magefile; mage itself is untouched and unaware.

Principles

  • Renderer, not build system. magetui.Deps reproduces the mg.Deps contract exactly — parallel, deduped, all siblings run to completion, errors aggregated. Only the presentation changes.
  • Explicit opt-in. Targets migrate one at a time via magetui.Target; unwrapped targets stay plain mage targets.
  • stdin untouched. No keyboard handling; interactive subprocesses keep working.
  • Degrades honestly. Non-TTY or MAGETUI_PROGRESS=plain gives prefixed line-by-line output for CI. NO_COLOR and color-profile degradation are automatic. Terminal progress (OSC 9;4 — Ghostty, Windows Terminal) is emitted where supported.

Environment

Environment overrides code:

Variable Values Effect
MAGETUI_PROGRESS auto | tty | plain Renderer selection (default: TTY detection)
MAGETUI_THEME color | greyscale | mono | ascii Theme selection
MAGETUI_OSC_PROGRESS on | off | percent OSC 9;4 terminal progress (default: emitter detection)
NO_COLOR any Disables color underneath any theme

Themes

Four embedded design intents — color (default), greyscale, mono (no color, full glyphs), ascii (glyph-poor terminals) — selectable via WithTheme(...) or MAGETUI_THEME. Custom themes are a struct of glyph strings and lipgloss styles.

Examples

The demo rig behind the GIF above:

mage -d examples            # demo: the all-green showcase
mage -d examples fail       # failure replay
mage -d examples panic      # panic presentation
mage -d examples everything # all of it at once; try ^C

Compatibility

Semver covers the Go API, the MAGETUI_* environment variables, exit codes (130 on SIGINT, 143 on SIGTERM), theme names, and plain mode's structural contract — one line per event, grep '^!' finds stderr, $ marks commands. Exact rendered output (padding, spacing, TUI frames, theme glyphs and palettes) is presentation, not API, and may change in any minor. The full surface: DESIGN.md §10.

Contributing

DESIGN.md is the source of truth for what magetui is; CONTRIBUTING.md for how it changes.

License

MIT

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

Constants

This section is empty.

Variables

View Source
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

func Deps(ctx context.Context, deps ...any)

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

func Output(ctx context.Context, cmd string, args ...string) (string, error)

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

func Printf(ctx context.Context, format string, a ...any)

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

func Run(ctx context.Context, cmd string, args ...string) error

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

func RunWith(ctx context.Context, env map[string]string, cmd string, args ...string) error

RunWith is Run with env overlaid on the process environment; $VAR expansion consults env first — sh.RunWith's contract.

func Status

func Status(ctx context.Context, text string)

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

func Target(ctx context.Context, fn func(context.Context) error, opts ...TargetOption) error

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.

func (Dep) ID

func (d Dep) ID() string

ID uses the same code-pointer identity as Deps.

func (Dep) Name

func (d Dep) Name() string

Name returns the step's display name, derived from the function name.

func (Dep) Run

func (d Dep) Run(ctx context.Context) error

Run executes the dependency. It exists for the Runnable/mg.Fn contract (mg.CtxDeps calls it); inside a magetui run, Deps schedules the underlying function itself.

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

type Runnable interface {
	Name() string
	ID() string
	Run(ctx context.Context) error
}

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.

Jump to

Keyboard shortcuts

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