progress

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 12 Imported by: 0

README

progress

Go Reference

progress is task visualization library for Go inspired by buildkit.

asciicast

Documentation

Overview

Package progress allows you to display task execution progress in the terminal. Tasks are visualized as a hierarchy inspired by the output of [docker build].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessEvents added in v0.2.0

func ProcessEvents(f console.File, name, mode string, events <-chan *TaskEvent) (<-chan struct{}, error)

Processes events from a channel and renders them to the console or trace. The mode can be "auto", "tty" or "plain". In "auto" mode, the console is used if available. In "tty" mode, the console is used and an error is returned if it is not available. In "plain" mode, the trace is used. When the events channel is closed, the last state is rendered and the function returns. The returned channel is closed when the rendering is complete. You'll most likely want to use DisplayProgress instead of this function.

Types

type CopyTask added in v0.7.0

type CopyTask struct {
	IOTask
	// contains filtered or unexported fields
}

CopyTask tracks the progress of copying from an io.Reader to an io.Writer

func (*CopyTask) Copy added in v0.7.0

func (t *CopyTask) Copy(dest io.Writer, src io.Reader) (int64, error)

Copy copies from src to dest and updates the progress.

func (*CopyTask) Reset added in v0.7.0

func (t *CopyTask) Reset(total uint64)

Reset resets the progress of the task, this is useful if you want to reuse the same task for multiple copies.

type IOTask added in v0.8.0

type IOTask struct {
	Task
}

IOTask is a task that can be used to display IO progress.

func (*IOTask) DisplayBar added in v0.8.0

func (t *IOTask) DisplayBar(b bool)

DisplayBar enables or disables the display of a progress bar.

func (*IOTask) DisplayETA added in v0.8.0

func (t *IOTask) DisplayETA(b bool)

DisplayETA enables or disables the display of the ETA.

func (*IOTask) DisplayRate added in v0.8.0

func (t *IOTask) DisplayRate(b bool)

DisplayRate enables or disables the display of the rate.

type ReaderTask

type ReaderTask struct {
	IOTask
	// contains filtered or unexported fields
}

ReaderTask tracks the progress of reading from an underlying io.Reader

func (*ReaderTask) Read

func (t *ReaderTask) Read(p []byte) (int, error)

Read reads from the underlying reader and updates the progress.

type RootTask added in v0.2.0

type RootTask struct {
	Task
}

RootTask is a task that can be used to close the channel of events.

func DisplayProgress added in v0.2.0

func DisplayProgress(f console.File, name, mode string) (*RootTask, <-chan struct{}, error)

DisplayProgress displays progress events to the console or trace. It is a convenience function that creates a RootTask and returns a channel that is closed when the rendering is complete. The caller has to make sure to close the RootTask after all Subtasks are completed. After the RootTask is closed, the remaining unprocesses events are rendered and the returned channel is closed.

func NewRootTask added in v0.7.0

func NewRootTask(ch chan *TaskEvent) *RootTask

NewRootTask creates a new RootTask that sends events to the given channel.

func (*RootTask) Close added in v0.2.0

func (r *RootTask) Close() error

Close closes the channel of events.

type Task

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

Task is the base type for all tasks. It provides the basic functionality for tasks like logging and launching subtasks.

func (*Task) Cached added in v0.6.0

func (t *Task) Cached()

Cached marks the task as cached.

func (*Task) Copier added in v0.7.0

func (t *Task) Copier(name string, total uint64, f func(*CopyTask) error) error

Copier launches a new subtask that can be used to copy from an io.Reader to an io.Writer. If total is 0, the task will not display a progress bar or ETA.

func (*Task) Execute added in v0.5.0

func (t *Task) Execute(name string, f func(*Task) error) error

Execute launches a new subtask by calling the given function and waits for it to complete. If f returns an error, the task will be marked as failed and the error will be returned.

func (*Task) Logger added in v0.5.0

func (t *Task) Logger() *TaskLogger

Logger returns a *TaskLogger that can be used to write logs to the task.

func (*Task) Name added in v0.7.0

func (t *Task) Name(name string)

Name sets the name of the task.

func (*Task) Reader added in v0.5.0

func (t *Task) Reader(name string, r io.Reader, total uint64, f func(*ReaderTask) error) error

Reader launches a new subtask that reads from the given reader. If total is 0, the task will not display a progress bar or ETA.

func (*Task) Writer added in v0.5.0

func (t *Task) Writer(name string, w io.Writer, total uint64, f func(*WriterTask) error) error

Writer launches a new subtask that writes to the given writer. If total is 0, the task will not display a progress bar or ETA.

type TaskEvent

type TaskEvent struct {
	ID       uint64 // unique ID for the task, must be > 0
	ParentID uint64 // ID of the parent task, 0 if no parent

	Name string // name of the task, this will be displayed in the header line

	StartTime, EndTime time.Time // start and end time of the task, used to calculate the duration
	IOStartTime        time.Time // start time of the IO task, used to calculate the rate and ETA
	IsDone             bool      // true if the task is done, finished tasks will be displayed differently

	Cached bool // true if the task is cached, cached tasks will be displayed differently when they are done

	// Current and Total are used to display a copy progress if Total is
	// unknown leave it as 0 and only Current will be displayed
	Current, Total uint64

	EnableDisplayRate  bool // true if displaying the rate should be enabled, only used for io tasks
	DisableDisplayRate bool // true if displaying the rate should be disabled, only used for io tasks
	EnableDisplayBar   bool // true if displaying the bar should be enabled, only used for io tasks

	EnableDisplayETA  bool // true if displaying the ETA should be enabled, only used for io tasks
	DisableDisplayETA bool // true if displaying the ETA should be disabled, only used for io tasks
	DisableDisplayBar bool // true if displaying the bar should be disabled, only used for io tasks

	HasErr bool  // true if the task has an error
	Err    error // error of the task, will be displayed in the task body when all tasks are done

	Logs []byte // logs of the task, will be displayed in the task body
}

TaskEvent carries all the information about tasks. You'll only need this if you do not want to use the Task interfaces and provide the events yourself.

type TaskLogger added in v0.8.0

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

TaskLogger implements io.Writer and writes logs to the task.

func (*TaskLogger) Write added in v0.8.0

func (l *TaskLogger) Write(p []byte) (int, error)

Write writes logs to the task.

type WriterTask

type WriterTask struct {
	IOTask
	// contains filtered or unexported fields
}

WriterTask tracks the progress of writing to an underlying io.Writer

func (*WriterTask) Write

func (t *WriterTask) Write(p []byte) (int, error)

Write writes to the underlying writer and updates the progress.

Directories

Path Synopsis
example
load command
uitest command

Jump to

Keyboard shortcuts

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