task

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package task provides functionality for managing and rendering the status of multiple tasks in the terminal.

Index

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.

func (*Manager) AddTask

func (m *Manager) AddTask(task *Task)

AddTask adds a new task to the manager if it does not already exist.

func (*Manager) Finish

func (m *Manager) Finish()

Finish stops the task manager's output loop and renders the final status of all tasks.

func (*Manager) Start

func (m *Manager) Start()

Start begins the task manager's output loop, which periodically renders the status of all tasks to the output. It only runs if the output is a terminal.

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

func NewTask(name, message string) *Task

NewTask creates a new task with the given name and message, and generates a unique ID for it.

func (*Task) Duration

func (t *Task) Duration() time.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) ID

func (t *Task) ID() string

ID returns the unique identifier of the task.

func (*Task) Message

func (t *Task) Message() string

Message returns the message of the task.

func (*Task) Name

func (t *Task) Name() string

Name returns the name of the task.

func (*Task) SetMessage

func (t *Task) SetMessage(message string)

SetMessage sets the task's message to the given value.

func (*Task) SetName

func (t *Task) SetName(name string)

SetName sets the task's name to the given value.

func (*Task) SetStatus

func (t *Task) SetStatus(status Status)

SetStatus sets the task's status to the given value.

func (*Task) Start

func (t *Task) Start()

Start sets the task's status to Started and records the start time.

func (*Task) Status

func (t *Task) Status() Status

Status returns the current status of the task.

func (*Task) Warning

func (t *Task) Warning()

Warning sets the task's status to Warning and records the end time.

Jump to

Keyboard shortcuts

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