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 ¶
- func ProcessEvents(f console.File, name, mode string, events <-chan *TaskEvent) (<-chan struct{}, error)
- type CopyTask
- type IOTask
- type ReaderTask
- type RootTask
- type Task
- func (t *Task) Cached()
- func (t *Task) Copier(name string, total uint64, f func(*CopyTask) error) error
- func (t *Task) Execute(name string, f func(*Task) error) error
- func (t *Task) Logger() *TaskLogger
- func (t *Task) Name(name string)
- func (t *Task) Reader(name string, r io.Reader, total uint64, f func(*ReaderTask) error) error
- func (t *Task) Writer(name string, w io.Writer, total uint64, f func(*WriterTask) error) error
- type TaskEvent
- type TaskLogger
- type WriterTask
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
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
DisplayBar enables or disables the display of a progress bar.
func (*IOTask) DisplayETA ¶ added in v0.8.0
DisplayETA enables or disables the display of the ETA.
func (*IOTask) DisplayRate ¶ added in v0.8.0
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
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
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
NewRootTask creates a new RootTask that sends events to the given channel.
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) Copier ¶ added in v0.7.0
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
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.
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.
type WriterTask ¶
type WriterTask struct {
IOTask
// contains filtered or unexported fields
}
WriterTask tracks the progress of writing to an underlying io.Writer