progress

package
v2.25.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModeAuto detect console capabilities.
	ModeAuto = Mode("auto")
	// ModeTTY use terminal capability for advanced rendering.
	ModeTTY = Mode("tty")
	// ModePlain dump raw events to output.
	ModePlain = Mode("plain")
	// ModeQuiet don't display events.
	ModeQuiet = Mode("quiet")
	// ModeJSON outputs a machine-readable JSON stream.
	ModeJSON = Mode("json")
)

Variables

This section is empty.

Functions

func EventId added in v2.23.4

func EventId(ctx context.Context) string

func IsNoOp

func IsNoOp(ctx context.Context) bool

func MaybeWriteError

func MaybeWriteError(ctx context.Context, err error) error

func Start

func Start(ctx context.Context, title string)

func Stop

func Stop(ctx context.Context)

func WithContextWriter

func WithContextWriter(ctx context.Context, writer Writer) context.Context

WithContextWriter adds the writer to the context.

func WithEventId added in v2.23.4

func WithEventId(ctx context.Context, id string) context.Context

func Write

func Write(ctx context.Context, events ...*Event)

Types

type Event

type Event struct {
	ID         string      `json:"id,omitempty"`
	Text       string      `json:"text,omitempty"`
	Status     EventStatus `json:"status,omitempty"`
	StatusText string      `json:"statusText,omitempty"`
	Current    int64       `json:"current,omitempty"`
	Percent    int         `json:"percent,omitempty"`
	Total      int64       `json:"total,omitempty"`
	StartTime  time.Time   `json:"startTime,omitzero"`
	EndTime    time.Time   `json:"endTime,omitzero"`
	// contains filtered or unexported fields
}

Event represents a progress event.

func BuildingEvent

func BuildingEvent(id string) *Event

BuildingEvent creates a new Building in progress Event.

func BuiltEvent

func BuiltEvent(id string) *Event

BuiltEvent creates a new built (done) *Event.

func Done

func Done(ctx context.Context, args ...any) *Event

func DoneEvent

func DoneEvent(id, verb string) *Event

DoneEvent creates a new <verb> done Event.

func Donef added in v2.23.4

func Donef(ctx context.Context, format string, args ...any) *Event

func Error

func Error(ctx context.Context, args ...any) *Event

func ErrorMessageEvent

func ErrorMessageEvent(id string, msg string) *Event

ErrorMessageEvent creates a new Error Event with a message.

func Errorf added in v2.23.4

func Errorf(ctx context.Context, format string, args ...any) *Event

func Info

func Info(ctx context.Context, args ...any) *Event

func InfoMessageEvent added in v2.23.4

func InfoMessageEvent(id string, msg string) *Event

InfoMessageEvent creates a new Error Event with a message.

func Infof added in v2.23.4

func Infof(ctx context.Context, format string, args ...any) *Event

func NewEvent

func NewEvent(id string, status EventStatus, statusText string) *Event

func PrintDone added in v2.23.4

func PrintDone(ctx context.Context, args ...any) *Event

PrintDone is like Done but also enforces that the plain writer will print the output. The plain writer normally skips Working and Done events.

func PrintDonef added in v2.23.4

func PrintDonef(ctx context.Context, format string, args ...any) *Event

PrintDonef is like Donef but also enforces that the plain writer will print the output. The plain writer normally skips Working and Done events.

func StartedEvent

func StartedEvent(id string) *Event

StartedEvent creates a new Started in progress Event.

func StartingEvent

func StartingEvent(id string) *Event

StartingEvent creates a new Starting in progress Event.

func StoppedEvent

func StoppedEvent(id string) *Event

StoppedEvent creates a new Stopping in progress Event.

func Warning

func Warning(ctx context.Context, args ...any) *Event

func WarningMessageEvent added in v2.23.4

func WarningMessageEvent(id string, msg string) *Event

WarningMessageEvent creates a new Error Event with a message.

func Warningf added in v2.23.4

func Warningf(ctx context.Context, format string, args ...any) *Event

func Working

func Working(ctx context.Context, args ...any) *Event

func WorkingEvent

func WorkingEvent(id, verb string) *Event

WorkingEvent creates a new <verb> in progress Event.

func Workingf added in v2.23.4

func Workingf(ctx context.Context, format string, args ...any) *Event

func (*Event) AddChild added in v2.23.4

func (e *Event) AddChild(status EventStatus, text, statusText string) *Event

func (*Event) PlainAlways added in v2.23.4

func (e *Event) PlainAlways() *Event

PlainAlways configures the event to always be printed when using the plain progress writer.

func (*Event) Pump added in v2.23.4

func (e *Event) Pump(ctx context.Context, status EventStatus) io.Writer

func (*Event) Spinner

func (e *Event) Spinner() string

func (*Event) WithText

func (e *Event) WithText(msg string) *Event

type EventStatus

type EventStatus int

EventStatus indicates the status of an action.

const (
	EventStatusWorking EventStatus = iota
	EventStatusDone
	EventStatusInfo
	EventStatusWarning
	EventStatusError
)

func (EventStatus) MarshalJSONTo added in v2.23.4

func (s EventStatus) MarshalJSONTo(out *jsontext.Encoder) error

func (EventStatus) String added in v2.23.4

func (s EventStatus) String() string

type Mode

type Mode string

type Writer

type Writer interface {
	// Start will start the writer in a new goroutine
	Start(ctx context.Context, progressTitle string)

	// Stop stops a started spinner
	Stop()

	// IsNoOp returns true for the noop spinner, false for every other spinner.
	IsNoOp() bool

	// Write writes progress events. If multiple events are given and the writer permits it, they will
	// end up in different spinners and be reported individually based on their ID.
	Write(...*Event)

	// TriggerRefresh triggers a refresh of event output on the tty writer
	TriggerRefresh()
}

Writer can write multiple progress events.

func ContextWriter

func ContextWriter(ctx context.Context) Writer

ContextWriter returns the writer from the context.

func NewWriter

func NewWriter(out, err io.Writer, mode Mode) Writer

NewWriter returns a new multi-progress writer.

Jump to

Keyboard shortcuts

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