progress

package
v2.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 16 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// ModeAuto detect console capabilities
	ModeAuto = "auto"
	// ModeTTY use terminal capability for advanced rendering
	ModeTTY = "tty"
	// ModePlain dump raw events to output
	ModePlain = "plain"
	// ModeQuiet don't display events
	ModeQuiet = "quiet"
)

Variables

View Source
var (
	DoneColor    colorFunc = aec.BlueF.Apply
	TimerColor   colorFunc = aec.BlueF.Apply
	CountColor   colorFunc = aec.YellowF.Apply
	WarningColor colorFunc = aec.YellowF.With(aec.Bold).Apply
	SuccessColor colorFunc = aec.GreenF.Apply
	ErrorColor   colorFunc = aec.RedF.With(aec.Bold).Apply
	PrefixColor  colorFunc = aec.CyanF.Apply
)
View Source
var Mode = ModeAuto

Mode define how progress should be rendered, either as ModePlain or ModeTTY

Functions

func NoColor added in v2.17.3

func NoColor()

func Run

func Run(ctx context.Context, pf progressFunc, out io.Writer) error

Run will run a writer and the progress function in parallel

func RunWithStatus

func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out io.Writer, progressTitle string) (string, error)

RunWithStatus will run a writer and the progress function in parallel and return a status

func RunWithTitle added in v2.18.0

func RunWithTitle(ctx context.Context, pf progressFunc, out io.Writer, progressTitle string) error

func WithContextWriter

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

WithContextWriter adds the writer to the context

Types

type Event

type Event struct {
	ID         string
	ParentID   string
	Text       string
	Status     EventStatus
	StatusText string
	Current    int64
	Percent    int

	Total int64
	// contains filtered or unexported fields
}

Event represents a progress event.

func CreatedEvent

func CreatedEvent(id string) Event

CreatedEvent creates a new Created (done) Event

func CreatingEvent

func CreatingEvent(id string) Event

CreatingEvent creates a new Create in progress Event

func ErrorEvent

func ErrorEvent(id string) Event

ErrorEvent creates a new Error Event

func ErrorMessageEvent

func ErrorMessageEvent(id string, msg string) Event

ErrorMessageEvent creates a new Error Event with message

func Exited added in v2.3.0

func Exited(id string) Event

Exited creates a new exited event

func Healthy added in v2.3.0

func Healthy(id string) Event

Healthy creates a new healthy event

func KilledEvent

func KilledEvent(id string) Event

KilledEvent creates a new Killed in progress Event

func KillingEvent

func KillingEvent(id string) Event

KillingEvent creates a new Killing in progress Event

func NewEvent

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

NewEvent new event

func RemovedEvent

func RemovedEvent(id string) Event

RemovedEvent creates a new removed (done) Event

func RemovingEvent

func RemovingEvent(id string) Event

RemovingEvent creates a new Removing in progress Event

func RestartedEvent

func RestartedEvent(id string) Event

RestartedEvent creates a new Restarted in progress Event

func RestartingEvent

func RestartingEvent(id string) Event

RestartingEvent creates a new Restarting in progress Event

func RunningEvent

func RunningEvent(id string) Event

RunningEvent creates a new Running in progress Event

func SkippedEvent added in v2.19.0

func SkippedEvent(id string, reason string) Event

SkippedEvent creates a new Skipped Event

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 StoppingEvent

func StoppingEvent(id string) Event

StoppingEvent creates a new Stopping in progress Event

func Waiting added in v2.3.0

func Waiting(id string) Event

Waiting creates a new waiting event

func (*Event) Spinner added in v2.17.0

func (e *Event) Spinner() any

type EventStatus

type EventStatus int

EventStatus indicates the status of an action

const (
	// Working means that the current task is working
	Working EventStatus = iota
	// Done means that the current task is done
	Done
	// Warning means that the current task has warning
	Warning
	// Error means that the current task has errored
	Error
)

type Writer

type Writer interface {
	Start(context.Context) error
	Stop()
	Event(Event)
	Events([]Event)
	TailMsgf(string, ...interface{})
}

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(ctx context.Context, out io.Writer, progressTitle string) (Writer, error)

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