progress

package
v2.0.0-...-9cab126 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

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"
)

Variables

View Source
var Mode = ModeAuto

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

Functions

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) (string, error)

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

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

func Exited(id string) Event

Exited creates a new exited event

func Healthy

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

func Waiting(id string) Event

Waiting creates a new waiting event

func (*Event) Spinner

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) (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