batch

package
v1.229.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package batch renders progress for concurrent operations. Scheduling belongs to callers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignProgress

func AlignProgress(left string, downloaded, total int64, width int) string

AlignProgress right-aligns real byte progress, omitting it when the label needs the width.

func Run

func Run(total int, work func(Observer) error) error

Run owns rendering while work emits progress. It drains events before returning.

Types

type Event

type Event struct {
	// Warning is a permanent diagnostic and does not count as a job.
	Warning string
	// Reset starts a new phase, clearing counts and active jobs.
	Reset bool
	ID    int
	Count int
	Label string
	// Version is displayed as a muted parenthesized suffix after the label.
	Version           string
	Phase             string
	Downloaded, Total int64
	// Fraction is caller-defined job progress in [0, 1], independent of completion.
	// The renderer retains the highest value across transitions and retries.
	Fraction float64
	// Bytes marks coalescible byte-only updates. Terminal events are never dropped.
	Bytes   bool
	Done    bool
	Outcome string
	Err     error
	Attempt int
}

Event describes a job's current state. IDs, unlike labels, must be unique within a run.

type Observer

type Observer func(Event)

Observer receives events serially from Run, even when producers are concurrent.

type Option

type Option func(*Renderer)

Option customizes the renderer without coupling it to job scheduling.

func WithToolchainStyle

func WithToolchainStyle() Option

WithToolchainStyle preserves the toolchain running-count footer.

type Renderer

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

Renderer owns an inline region. All methods must be called by its owner goroutine.

func New

func New(total int, live bool, options ...Option) *Renderer

New creates a renderer using the existing Atmos terminal theme.

func (*Renderer) Clear

func (r *Renderer) Clear()

Clear removes the live region; completed lines remain in scrollback.

func (*Renderer) Complete

func (r *Renderer) Complete(id int, output func())

Complete replaces an active row with caller-formatted permanent output. The callback executes synchronously on the renderer's owner goroutine.

func (*Renderer) Tick

func (r *Renderer) Tick()

Tick advances the spinner without animation commands that race model updates.

func (*Renderer) Update

func (r *Renderer) Update(event *Event)

Update consumes a non-nil transition without allowing worker output into the live region. It snapshots the event immediately; callers retain ownership of their event.

Jump to

Keyboard shortcuts

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