Help us shape the future of Go! Take the 2026 Go Developer Survey

progress

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package progress is how the engine says what a slow command is doing: named steps, one running at a time, and one-off notes. The CLI draws them (an animated checklist on a terminal, plain lines elsewhere); the engine never formats for a terminal. A nil Progress in the engine, or Nop, prints nothing.

Every implementation follows the same rules: starting a step finishes the running one as done (reaching the next step means the last one worked); Update, Done and Fail on an ended step do nothing; every method is safe from any goroutine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Kind  string
	Text  string
	Level NoteLevel
}

Event is one thing a Recorder saw. Kind is "step", "update", "done", "fail" or "note"; Level is set for notes only.

type NoteLevel

type NoteLevel int

NoteLevel is how much a note matters.

const (
	// Info is a remark: drawn as a dim "·" line.
	Info NoteLevel = iota
	// Warn is something a person should notice: a yellow "!" line.
	Warn
)

type Progress

type Progress interface {
	// Step starts a step; it becomes the running (spinning) line.
	Step(text string) Step
	// Note prints a one-off line that stays, above the running step.
	Note(level NoteLevel, text string)
}

Progress receives a command's steps and notes.

func Lines

func Lines(w io.Writer) Progress

Lines writes progress as plain lines, for pipes, files, CI, --json and TERM=dumb: each step's start and each note as one line, as Ghostbranch did before 6.4a. A step explicitly ended by Done or Fail prints one more line only when it carries news, that is when its text changed since it started (an Update, or a Done with a new text): "ok: <text>" or "failed: <text>". A step ended by the next step prints nothing. The prefixes are ASCII so logs stay greppable (owner, 2026-10-11; R15). Updates themselves print nothing. A nil w prints nothing.

func Nop

func Nop() Progress

Nop prints nothing.

type Recorder

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

Recorder keeps every step, update and note in order, for tests. The zero value is ready to use.

func (*Recorder) Events

func (r *Recorder) Events() []Event

Events returns a copy of everything seen, in order.

func (*Recorder) Note

func (r *Recorder) Note(level NoteLevel, text string)

func (*Recorder) Notes

func (r *Recorder) Notes() []string

Notes is every note's text, in order.

func (*Recorder) Running

func (r *Recorder) Running() bool

Running reports whether a step was started and never ended.

func (*Recorder) Step

func (r *Recorder) Step(text string) Step

func (*Recorder) Steps

func (r *Recorder) Steps() []string

Steps is the text each step started with, in order.

func (*Recorder) String

func (r *Recorder) String() string

String is one "kind: text" line per event, for test failure messages.

func (*Recorder) Updates

func (r *Recorder) Updates() []string

Updates is every update's text, in order.

type Step

type Step interface {
	// Update replaces the running step's text.
	Update(text string)
	// Done ends the step with a ✓. text replaces the step's text (a past
	// tense, say); "" keeps it.
	Done(text string)
	// Fail ends the step with a ✗ and its current text.
	Fail()
}

Step is one running step.

Jump to

Keyboard shortcuts

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