progress

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package progress renders a CLI progress display: a live region of per-step lines, each animating its own spinner and bubbles-rendered progress bar, plus a stream of completed steps that get promoted in place (rewritten as a past-tense title with their child tree) and scroll into history as new steps start.

Progress satisfies the engine.ProgressReporter interface (StartStage / AdvanceStage / CompleteStage) so the pipeline can drive coarse progress events, while command code can also open finer-grained step handles via Start / StartWithDoneLabel.

Index

Constants

View Source
const (
	CheckMark   = "✔"
	CrossMark   = "✘"
	WarningMark = "⚠"
)

Visual marks rendered before completed-step / child labels.

Variables

This section is empty.

Functions

This section is empty.

Types

type Child

type Child struct {
	Icon   string // e.g. CheckMark, CrossMark, WarningMark, or "" for a plain item
	Label  string // e.g. "Maven Detector", "subproject-a"
	Detail string // e.g. "[59 packages]"
}

Child describes one sub-item rendered beneath a completed task.

type Progress

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

Progress renders the live region. Safe for concurrent use.

func New

func New(writer io.Writer, enabled bool, label string) *Progress

New creates a Progress instance. When enabled is false, all methods are no-ops. A non-empty initial label opens an implicit step that disappears silently once any explicit Start / StartStage is called.

func (*Progress) Advance

func (p *Progress) Advance(label string)

Advance flushes any prior implicit/in-flight steps and starts a new labeled step. Preserves the legacy single-spinner API for callers like scan_cmd's "Writing SBOM output" transition. Each silently-promoted prior step gets its own hold (sequential, so the user sees each one transition).

func (*Progress) AdvanceStage

func (p *Progress) AdvanceStage(label string, completed, total int)

func (*Progress) CompleteStage

func (p *Progress) CompleteStage(label string, total int)

func (*Progress) CompleteStep

func (p *Progress) CompleteStep(doneLabel string, children []Child)

CompleteStep finalises the step matching doneLabel (or the most-recent stepActive / stepFinishing step) with the supplied children. Blocks for p.minStepDuration after the state transition (see holdAfterDone) so each step has its own visible ✔ window before the next CLI operation proceeds.

func (*Progress) Detail

func (p *Progress) Detail(label, detail string)

Detail updates the hint on the step keyed by activeLabel. Implements the engine's DetailProgressReporter interface.

func (*Progress) Fail

func (p *Progress) Fail(label string)

Fail promotes the most-recent active step with a ✘ icon and stops the renderer.

func (*Progress) SeparateReport

func (p *Progress) SeparateReport()

SeparateReport writes a blank line between the progress output and any human-readable report that follows on stdout.

func (*Progress) Stage

func (p *Progress) Stage(text string)

Stage updates the hint on the most-recent active step. Kept for backwards-compatibility with the legacy single-spinner API.

func (*Progress) Start

func (p *Progress) Start(id, activeLabel string) *Step

Start opens a new step in the live region.

func (*Progress) StartStage

func (p *Progress) StartStage(label string, total int)

StartStage / AdvanceStage / CompleteStage satisfy engine.ProgressReporter. They route engine-emitted stage events through the label-keyed shim so the CLI can later supply a past-tense label + children via CompleteStep.

func (*Progress) StartWithDoneLabel

func (p *Progress) StartWithDoneLabel(id, activeLabel, doneLabel string) *Step

StartWithDoneLabel opens a new step and pre-registers its past-tense label so subsequent CompleteStep(doneLabel, …) finds the same step.

func (*Progress) Stop

func (p *Progress) Stop()

Stop halts the renderer without writing a final line. Cursor visibility is restored. Subsequent calls are no-ops.

func (*Progress) Success

func (p *Progress) Success(label string)

Success promotes the most-recent active step (or the step matching label via pastToID) and stops the renderer. Subsequent calls are no-ops.

func (*Progress) SuccessWithChildren

func (p *Progress) SuccessWithChildren(label string, children []Child)

SuccessWithChildren promotes the most-recent active step with children and stops the renderer.

type Step

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

Step is the handle for one line in the live region. It is returned by Start / StartWithDoneLabel and used by callers that want to drive a dedicated progress line directly (rather than via the label-keyed shim).

func (*Step) Advance

func (s *Step) Advance()

Advance increments completed by one.

func (*Step) Complete

func (s *Step) Complete(doneLabel string, children []Child)

Complete marks the step as succeeded with the supplied past-tense label and child tree. The renderer holds the line for p.minStepDuration after this call (via the doneAt stamp) and the call itself blocks for the same hold, so each step has its own visible ✔ window before the next operation proceeds.

func (*Step) Fail

func (s *Step) Fail(doneLabel string)

Fail marks the step as failed with the supplied past-tense label. Blocks for p.minStepDuration after the state transition (same hold semantics as Complete) so failures stay readable.

func (*Step) SetDetail

func (s *Step) SetDetail(text string)

SetDetail updates the hint text shown to the right of the bar on this step.

func (*Step) SetProgress

func (s *Step) SetProgress(completed, total int)

SetProgress replaces completed/total atomically.

func (*Step) SetTotal

func (s *Step) SetTotal(n int)

SetTotal sets the denominator for this step's progress bar.

Jump to

Keyboard shortcuts

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