Documentation
¶
Overview ¶
Package nesgress provides hierarchical progress reporting with nested spinner displays.
The name "nesgress" is a pun on "nested progress", reflecting the library's ability to display hierarchical, nested progress operations in the terminal.
Features ¶
- Hierarchical progress display with parent-child relationships
- Thread-safe concurrent operation support
- Spinner animations using charmbracelet/huh
- Success/failure indicators with timing information
- Persistent mode for long-running operations with accomplishments
- Pause/resume support for interactive prompts
Basic Usage ¶
display := nesgress.NewProgressDisplay(os.Stdout)
defer display.Close()
display.Start("Installing packages")
// ... do work ...
display.Finish("Packages installed")
Nested Operations ¶
display.Start("Setting up environment")
display.Start("Downloading dependencies")
display.Finish("Dependencies downloaded")
display.Start("Compiling")
display.Finish("Compiled")
display.Finish("Environment ready")
Persistent Mode ¶
For long-running operations where you want to show intermediate accomplishments:
display.StartPersistent("Deploying application")
display.LogAccomplishment("Built container")
display.LogAccomplishment("Pushed to registry")
display.FinishPersistent("Deployment complete")
Pause/Resume for Interactive Input ¶
When you need to prompt for user input:
display.Pause() // Stops spinners, clears line // ... show prompt, get input ... display.Resume() // Restarts spinners
Noop Implementation ¶
For testing or when progress display should be disabled:
display := nesgress.NewNoopProgressDisplay()
Index ¶
- type NoopProgressDisplay
- func (n *NoopProgressDisplay) Clear() error
- func (n *NoopProgressDisplay) Close() error
- func (n *NoopProgressDisplay) Fail(message string, err error) error
- func (n *NoopProgressDisplay) FailPersistent(message string, err error) error
- func (n *NoopProgressDisplay) Finish(message string) error
- func (n *NoopProgressDisplay) FinishPersistent(message string) error
- func (n *NoopProgressDisplay) IsActive() bool
- func (n *NoopProgressDisplay) IsPaused() bool
- func (n *NoopProgressDisplay) LogAccomplishment(message string) error
- func (n *NoopProgressDisplay) Pause() error
- func (n *NoopProgressDisplay) Resume() error
- func (n *NoopProgressDisplay) Start(message string) error
- func (n *NoopProgressDisplay) StartPersistent(message string) error
- func (n *NoopProgressDisplay) Update(message string) error
- type ProgressDisplay
- func (p *ProgressDisplay) Clear() error
- func (p *ProgressDisplay) Close() error
- func (p *ProgressDisplay) Fail(message string, err error) error
- func (p *ProgressDisplay) FailPersistent(message string, err error) error
- func (p *ProgressDisplay) Finish(message string) error
- func (p *ProgressDisplay) FinishPersistent(message string) error
- func (p *ProgressDisplay) GetOutputSafely() string
- func (p *ProgressDisplay) IsActive() bool
- func (p *ProgressDisplay) IsPaused() bool
- func (p *ProgressDisplay) LogAccomplishment(message string) error
- func (p *ProgressDisplay) Pause() error
- func (p *ProgressDisplay) Resume() error
- func (p *ProgressDisplay) Start(message string) error
- func (p *ProgressDisplay) StartPersistent(message string) error
- func (p *ProgressDisplay) Update(message string) error
- type ProgressOperation
- type ProgressReporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NoopProgressDisplay ¶
type NoopProgressDisplay struct{}
NoopProgressDisplay is a progress display that does nothing.
func NewNoopProgressDisplay ¶
func NewNoopProgressDisplay() *NoopProgressDisplay
NewNoopProgressDisplay creates a progress display that does nothing.
func (*NoopProgressDisplay) Fail ¶
func (n *NoopProgressDisplay) Fail(message string, err error) error
Fail does nothing.
func (*NoopProgressDisplay) FailPersistent ¶
func (n *NoopProgressDisplay) FailPersistent(message string, err error) error
FailPersistent does nothing.
func (*NoopProgressDisplay) Finish ¶
func (n *NoopProgressDisplay) Finish(message string) error
Finish does nothing.
func (*NoopProgressDisplay) FinishPersistent ¶
func (n *NoopProgressDisplay) FinishPersistent(message string) error
FinishPersistent does nothing.
func (*NoopProgressDisplay) IsActive ¶
func (n *NoopProgressDisplay) IsActive() bool
IsActive always returns false.
func (*NoopProgressDisplay) IsPaused ¶
func (n *NoopProgressDisplay) IsPaused() bool
IsPaused always returns false.
func (*NoopProgressDisplay) LogAccomplishment ¶
func (n *NoopProgressDisplay) LogAccomplishment(message string) error
LogAccomplishment does nothing.
func (*NoopProgressDisplay) Resume ¶
func (n *NoopProgressDisplay) Resume() error
Resume does nothing.
func (*NoopProgressDisplay) Start ¶
func (n *NoopProgressDisplay) Start(message string) error
Start does nothing.
func (*NoopProgressDisplay) StartPersistent ¶
func (n *NoopProgressDisplay) StartPersistent(message string) error
StartPersistent does nothing.
func (*NoopProgressDisplay) Update ¶
func (n *NoopProgressDisplay) Update(message string) error
Update does nothing.
type ProgressDisplay ¶
type ProgressDisplay struct {
// contains filtered or unexported fields
}
ProgressDisplay provides hierarchical progress reporting with npm-style output.
func NewProgressDisplay ¶
func NewProgressDisplay(output io.Writer) *ProgressDisplay
NewProgressDisplay creates a new hierarchical progress display.
func (*ProgressDisplay) Clear ¶
func (p *ProgressDisplay) Clear() error
Clear stops all progress operations without displaying completion messages.
func (*ProgressDisplay) Close ¶
func (p *ProgressDisplay) Close() error
Close ensures proper cleanup of terminal state.
func (*ProgressDisplay) Fail ¶
func (p *ProgressDisplay) Fail(message string, err error) error
Fail completes the current progress operation with an error.
func (*ProgressDisplay) FailPersistent ¶
func (p *ProgressDisplay) FailPersistent(message string, err error) error
FailPersistent completes persistent progress with failure.
func (*ProgressDisplay) Finish ¶
func (p *ProgressDisplay) Finish(message string) error
Finish completes the current progress operation successfully.
func (*ProgressDisplay) FinishPersistent ¶
func (p *ProgressDisplay) FinishPersistent(message string) error
FinishPersistent completes persistent progress with success.
func (*ProgressDisplay) GetOutputSafely ¶
func (p *ProgressDisplay) GetOutputSafely() string
GetOutputSafely returns buffer content in a thread-safe manner when using bytes.Buffer.
func (*ProgressDisplay) IsActive ¶
func (p *ProgressDisplay) IsActive() bool
IsActive returns true if there are any active progress operations.
func (*ProgressDisplay) IsPaused ¶
func (p *ProgressDisplay) IsPaused() bool
IsPaused returns whether the progress display is currently paused
func (*ProgressDisplay) LogAccomplishment ¶
func (p *ProgressDisplay) LogAccomplishment(message string) error
LogAccomplishment logs an accomplishment that stays visible.
func (*ProgressDisplay) Pause ¶
func (p *ProgressDisplay) Pause() error
Pause temporarily stops all spinner operations for interactive commands
func (*ProgressDisplay) Resume ¶
func (p *ProgressDisplay) Resume() error
Resume restarts spinner operations after interactive commands complete
func (*ProgressDisplay) Start ¶
func (p *ProgressDisplay) Start(message string) error
Start begins a new progress operation with the given message.
func (*ProgressDisplay) StartPersistent ¶
func (p *ProgressDisplay) StartPersistent(message string) error
StartPersistent begins a persistent progress operation that shows accomplishments.
func (*ProgressDisplay) Update ¶
func (p *ProgressDisplay) Update(message string) error
Update modifies the message of the current progress operation.
type ProgressOperation ¶
type ProgressOperation struct {
Message string
StartTime time.Time
Level int
Success bool
Error error
CancelFunc context.CancelFunc
// contains filtered or unexported fields
}
ProgressOperation represents an active progress operation.
func (*ProgressOperation) IsDone ¶
func (op *ProgressOperation) IsDone() bool
IsDone returns whether this operation is completed.
func (*ProgressOperation) SetDone ¶
func (op *ProgressOperation) SetDone()
SetDone marks this operation as completed.
type ProgressReporter ¶
type ProgressReporter interface {
io.Closer
// Start begins a new progress operation with the given message
Start(message string) error
// Update modifies the message of the current progress operation
Update(message string) error
// Finish completes the current progress operation successfully
Finish(message string) error
// Fail completes the current progress operation with an error
Fail(message string, err error) error
// StartPersistent begins a persistent progress operation that shows accomplishments
StartPersistent(message string) error
// LogAccomplishment logs an accomplishment that stays visible
LogAccomplishment(message string) error
// FinishPersistent completes persistent progress with success
FinishPersistent(message string) error
// FailPersistent completes persistent progress with failure
FailPersistent(message string, err error) error
// Clear stops all progress operations without displaying completion messages
Clear() error
// Pause temporarily stops all spinner operations for interactive commands
Pause() error
// Resume restarts spinner operations after interactive commands complete
Resume() error
// IsActive returns true if there are any active progress operations
IsActive() bool
// IsPaused returns whether the progress display is currently paused
IsPaused() bool
}
ProgressReporter defines the interface for hierarchical progress reporting.