nesgress

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-nesgress

A Go library for 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

Installation

go get github.com/MrPointer/go-nesgress

Usage

Basic Progress
package main

import (
    "os"
    "time"

    "github.com/MrPointer/go-nesgress"
)

func main() {
    display := nesgress.NewProgressDisplay(os.Stdout)
    defer display.Close()

    display.Start("Installing packages")
    time.Sleep(2 * time.Second) // Simulate work
    display.Finish("Packages installed")
}

Output:

✓ Packages installed (took 2s)
Nested Operations
display.Start("Setting up environment")

    display.Start("Downloading dependencies")
    time.Sleep(1 * time.Second)
    display.Finish("Dependencies downloaded")

    display.Start("Compiling")
    time.Sleep(500 * time.Millisecond)
    display.Finish("Compiled")

display.Finish("Environment ready")

While running, shows hierarchical context:

⠋ Setting up environment: Downloading dependencies
Handling Errors
display.Start("Connecting to database")
err := connectToDatabase()
if err != nil {
    display.Fail("Connection failed", err)
    return
}
display.Finish("Connected")

Output on failure:

✗ Connection failed
  Error: connection refused
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.LogAccomplishment("Updated load balancer")

display.FinishPersistent("Deployment complete")

Output:

   ✓ Built container
   ✓ Pushed to registry
   ✓ Updated load balancer
✓ Deploying application (took 45s)
Pause/Resume for Interactive Input

When you need to prompt for user input:

display.Start("Processing files")

// Need to ask user something
display.Pause()
fmt.Print("Continue? [y/n]: ")
// ... get input ...
display.Resume()

display.Finish("Files processed")
Noop Implementation

For testing or when progress display should be disabled:

var display nesgress.ProgressReporter

if verbose {
    display = nesgress.NewProgressDisplay(os.Stdout)
} else {
    display = nesgress.NewNoopProgressDisplay()
}

// Same API, no output when using Noop
display.Start("Working...")
display.Finish("Done")

API Reference

ProgressReporter Interface
type ProgressReporter interface {
    io.Closer
    Start(message string) error
    Update(message string) error
    Finish(message string) error
    Fail(message string, err error) error
    StartPersistent(message string) error
    LogAccomplishment(message string) error
    FinishPersistent(message string) error
    FailPersistent(message string, err error) error
    Clear() error
    Pause() error
    Resume() error
    IsActive() bool
    IsPaused() bool
}
Functions
  • NewProgressDisplay(output io.Writer) *ProgressDisplay - Create a new progress display
  • NewNoopProgressDisplay() *NoopProgressDisplay - Create a no-op progress display

Dependencies

License

MIT License - see LICENSE for details.

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

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) Clear

func (n *NoopProgressDisplay) Clear() error

Clear does nothing.

func (*NoopProgressDisplay) Close

func (n *NoopProgressDisplay) Close() error

Close 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) Pause

func (n *NoopProgressDisplay) Pause() error

Pause 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.

Jump to

Keyboard shortcuts

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