progress

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package progress provides terminal progress indicators (spinners, bars, status).

Example (Combined)

Example showing combined usage in a realistic scenario.

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/jmylchreest/tinct/internal/ui/progress"
)

func main() {
	fmt.Println("Installing plugins...")

	// Step 1: Checking with spinner
	spinner := progress.NewSpinner("Checking plugin repository...").WithWriter(os.Stdout)
	spinner.Start()
	time.Sleep(time.Second)
	spinner.Stop("Repository checked ✓")

	// Step 2: Download with progress bar
	bar := progress.NewProgressBar(1024*1024*5, "Downloading plugin").WithWriter(os.Stdout)
	for i := int64(0); i < 1024*1024*5; i += 1024 * 256 {
		bar.Set(i)
		time.Sleep(10 * time.Millisecond)
	}
	bar.Finish("Plugin downloaded ✓")

	// Step 3: Installing with spinner
	spinner2 := progress.NewSpinner("Installing plugin...").WithWriter(os.Stdout)
	spinner2.Start()
	time.Sleep(time.Second)
	spinner2.Stop("Installation complete ✓")

	fmt.Println("\nAll done!")
}
Output:
Installing plugins...
Repository checked ✓
Plugin downloaded ✓
Installation complete ✓

All done!

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	SpinnerDots    = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
	SpinnerLine    = []string{"-", "\\", "|", "/"}
	SpinnerArrow   = []string{"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"}
	SpinnerCircle  = []string{"◐", "◓", "◑", "◒"}
	SpinnerDefault = SpinnerDots
)

Spinner characters for different animation styles.

Functions

This section is empty.

Types

type ProgressBar

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

ProgressBar displays a progress bar with percentage.

Example

ExampleProgressBar demonstrates a progress bar for downloads.

package main

import (
	"os"
	"time"

	"github.com/jmylchreest/tinct/internal/ui/progress"
)

func main() {
	total := int64(1024 * 1024 * 10) // 10 MB
	bar := progress.NewProgressBar(total, "Downloading plugin").WithWriter(os.Stdout)

	// Simulate download in chunks
	for downloaded := int64(0); downloaded < total; downloaded += 1024 * 512 {
		bar.Set(downloaded)
		time.Sleep(50 * time.Millisecond)
	}

	bar.Finish("Download complete ✓")
}
Output:
Download complete ✓

func NewProgressBar

func NewProgressBar(total int64, prefix string) *ProgressBar

NewProgressBar creates a new progress bar.

func (*ProgressBar) Add

func (p *ProgressBar) Add(delta int64)

Add increments the progress by delta.

func (*ProgressBar) Finish

func (p *ProgressBar) Finish(finalMessage string)

Finish completes the progress bar and shows 100%.

func (*ProgressBar) Set

func (p *ProgressBar) Set(current int64)

Set updates the current progress value.

func (*ProgressBar) WithWidth

func (p *ProgressBar) WithWidth(width int) *ProgressBar

WithWidth sets the progress bar width.

func (*ProgressBar) WithWriter

func (p *ProgressBar) WithWriter(w io.Writer) *ProgressBar

WithWriter sets the output writer.

type Spinner

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

Spinner displays an animated spinner with a message.

Example

ExampleSpinner demonstrates a spinner for long-running operations.

package main

import (
	"os"
	"time"

	"github.com/jmylchreest/tinct/internal/ui/progress"
)

func main() {
	spinner := progress.NewSpinner("Processing...").WithWriter(os.Stdout)
	spinner.Start()

	// Simulate work
	time.Sleep(2 * time.Second)

	spinner.Stop("Processing complete ✓")
}
Output:
Processing complete ✓
Example (Update)

ExampleSpinner_update demonstrates updating spinner message.

package main

import (
	"time"

	"github.com/jmylchreest/tinct/internal/ui/progress"
)

func main() {
	spinner := progress.NewSpinner("Step 1...")
	spinner.Start()

	time.Sleep(500 * time.Millisecond)
	spinner.UpdateMessage("Step 2...")

	time.Sleep(500 * time.Millisecond)
	spinner.UpdateMessage("Step 3...")

	time.Sleep(500 * time.Millisecond)
	spinner.Stop("All steps complete ✓")
}

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the default animation.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop(finalMessage string)

Stop stops the spinner and optionally shows a final message.

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(message string)

UpdateMessage changes the spinner message while it's running.

func (*Spinner) WithFrames

func (s *Spinner) WithFrames(frames []string) *Spinner

WithFrames sets custom spinner frames.

func (*Spinner) WithInterval

func (s *Spinner) WithInterval(d time.Duration) *Spinner

WithInterval sets the animation interval.

func (*Spinner) WithWriter

func (s *Spinner) WithWriter(w io.Writer) *Spinner

WithWriter sets the output writer.

type Status

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

Status represents a simple status line that can be updated.

Example

ExampleStatus demonstrates a simple status line.

package main

import (
	"os"
	"time"

	"github.com/jmylchreest/tinct/internal/ui/progress"
)

func main() {
	status := progress.NewStatus("Checking repositories...").WithWriter(os.Stdout)

	time.Sleep(500 * time.Millisecond)
	status.Update("Downloading manifest...")

	time.Sleep(500 * time.Millisecond)
	status.Update("Verifying checksums...")

	time.Sleep(500 * time.Millisecond)
	status.Finish("Repository sync complete ✓")
}
Output:
Repository sync complete ✓

func NewStatus

func NewStatus(message string) *Status

NewStatus creates a new status line.

func (*Status) Clear

func (s *Status) Clear()

Clear removes the status line.

func (*Status) Finish

func (s *Status) Finish(finalMessage string)

Finish clears the status line and optionally prints a final message.

func (*Status) Update

func (s *Status) Update(message string)

Update changes the status message.

func (*Status) WithWriter

func (s *Status) WithWriter(w io.Writer) *Status

WithWriter sets the output writer.

Jump to

Keyboard shortcuts

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