Documentation
¶
Overview ¶
Package task provides functionality for managing and rendering the status of multiple tasks in the terminal.
Index ¶
- type Manager
- type Status
- type Task
- func (t *Task) Duration() time.Duration
- func (t *Task) Error()
- func (t *Task) Finish()
- func (t *Task) ID() string
- func (t *Task) Message() string
- func (t *Task) Name() string
- func (t *Task) SetMessage(message string)
- func (t *Task) SetName(name string)
- func (t *Task) SetStatus(status Status)
- func (t *Task) Start()
- func (t *Task) Status() Status
- func (t *Task) Warning()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
Out *os.File // the output file (typically the terminal) where task statuses are rendered
Tasks []*Task // the list of tasks being managed
RefreshRate time.Duration // the interval at which the task statuses are refreshed in the terminal
// contains filtered or unexported fields
}
Manager manages and renders the status of multiple tasks in the terminal.
func NewManager ¶
func NewManager() *Manager
NewManager creates a new instance of Manager with default values.
type Status ¶
type Status int
Status represents the current state of a task in the task manager.
const ( // NotStarted represents a task that has not started yet. NotStarted Status = iota // Started represents a task that has started. Started // Finished represents a task that has finished successfully. Finished // Warning represents a task that has finished with a warning. Warning // Error represents a task that has finished with an error. Error )
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task represents a unit of work with a name, message, status, and timing information.
func NewTask ¶
NewTask creates a new task with the given name and message, and generates a unique ID for it.
func (*Task) Duration ¶
Duration returns the duration of the task based on its status. If the task is finished, warning, or error, it calculates the duration from the start to the end time. If the task is still running, it calculates the duration from the start time to the current time.
func (*Task) Error ¶
func (t *Task) Error()
Error sets the task's status to Error and records the end time.
func (*Task) Finish ¶
func (t *Task) Finish()
Finish sets the task's status to Finished and records the end time.
func (*Task) SetMessage ¶
SetMessage sets the task's message to the given value.