Documentation
¶
Overview ¶
Package progress provides terminal progress bar rendering with stage support. It handles ANSI escape codes for line clearing and overwriting to show updating progress without scrolling the terminal.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderBar ¶
RenderBar creates a visual progress bar string. width is the number of characters for the bar (excluding brackets). Returns a string like "[████████░░░░░░░░░░░░]"
func RenderBarASCII ¶
RenderBarASCII creates a progress bar using ASCII characters only. Returns a string like "[========------------]"
Types ¶
type MultiStageRenderer ¶
type MultiStageRenderer struct {
// contains filtered or unexported fields
}
MultiStageRenderer handles displaying progress to a terminal with stage support. It manages line clearing and overwriting for smooth progress updates.
func NewMultiStageRenderer ¶
func NewMultiStageRenderer(w io.Writer) *MultiStageRenderer
NewMultiStageRenderer creates a new multi-stage progress renderer that writes to w. Default bar width is 20 characters, description width is 34 characters.
func (*MultiStageRenderer) Update ¶
func (r *MultiStageRenderer) Update(info StageInfo)
Update displays the current progress state. When Done is false, the line is overwritten on subsequent calls. When Done is true, a newline is printed and the next update starts on a new line.
func (*MultiStageRenderer) WithBarWidth ¶
func (r *MultiStageRenderer) WithBarWidth(width int) *MultiStageRenderer
WithBarWidth sets the width of the progress bar in characters.
func (*MultiStageRenderer) WithDescWidth ¶
func (r *MultiStageRenderer) WithDescWidth(width int) *MultiStageRenderer
WithDescWidth sets the width of the description field in characters.
type SingleStageRenderer ¶
type SingleStageRenderer struct {
// contains filtered or unexported fields
}
SingleStageRenderer handles displaying single-stage progress to a terminal. Use this for progress tracking without multiple stages.
func NewSingleStageRenderer ¶
func NewSingleStageRenderer(w io.Writer) *SingleStageRenderer
NewSingleStageRenderer creates a new single-stage progress renderer that writes to w. Default bar width is 40 characters, text width is 30 characters.
func (*SingleStageRenderer) Done ¶
func (r *SingleStageRenderer) Done(message string)
Done clears the progress line and optionally prints a completion message. If message is empty, just clears the line.
func (*SingleStageRenderer) Update ¶
func (r *SingleStageRenderer) Update(current, total int, text string)
Update displays the current progress state. The line is overwritten on subsequent calls. Call Done() when complete to print a newline.
func (*SingleStageRenderer) WithBarWidth ¶
func (r *SingleStageRenderer) WithBarWidth(width int) *SingleStageRenderer
WithBarWidth sets the width of the progress bar in characters.
func (*SingleStageRenderer) WithTextWidth ¶
func (r *SingleStageRenderer) WithTextWidth(width int) *SingleStageRenderer
WithTextWidth sets the width of the text field in characters.
type StageInfo ¶
type StageInfo struct {
Stage int // Current stage number (1-based)
TotalStages int // Total number of stages
Description string // What's happening in this stage
Current int // Current item within stage (0 if not applicable)
Total int // Total items in stage (0 if not applicable)
Done bool // True if this stage is complete
Text string // Optional extra text (e.g., current item name)
}
StageInfo contains information about the current progress state.