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 ¶
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 ✓")
}
Output:
func NewSpinner ¶
NewSpinner creates a new spinner with the default animation.
func (*Spinner) UpdateMessage ¶
UpdateMessage changes the spinner message while it's running.
func (*Spinner) WithFrames ¶
WithFrames sets custom spinner frames.
func (*Spinner) WithInterval ¶
WithInterval sets the animation interval.
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 ✓