[go-fan] Go Module Review: briandowns/spinner #5094
Closed
Replies: 2 comments 1 reply
-
|
/plan |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
⚓ Avast! This discussion be marked as outdated by Go Fan. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🐹 Go Fan Report: briandowns/spinner
Module Overview
The
github.com/briandowns/spinnermodule is a simple and elegant terminal spinner library that provides visual feedback during long-running operations. It offers 90+ character sets, customizable colors, dynamic message updates, and automatic TTY detection—perfect for CLI applications like gh-aw.Current Version: v1.23.2 (Latest as of January 2025!)
Full Module Details
Key Features
Repository Stats
Current Usage in gh-aw
The project uses spinner excellently through a custom
SpinnerWrapperimplementation that:✅ Automatically detects TTY environments using go-isatty
✅ Provides conditional behavior (no-op when not in terminal)
✅ Uses consistent styling (braille dots, 100ms speed, cyan color)
✅ Supports dynamic message updates
Usage Pattern Implementation
SpinnerWrapper Design
Located in
pkg/console/spinner.go, the wrapper provides:Methods:
NewSpinner(message)- Creates spinner with TTY detectionStart()- Begins animation (if enabled)Stop()- Stops animationUpdateMessage(message)- Updates display textIsEnabled()- Checks if spinner is activeConfiguration
⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏)Usage Across Codebase
The spinner appears in 9 locations providing feedback for:
Network Operations (5 locations)
Download Operations (1 location)
Cancellation Operations (2 locations)
Retry Operations (1 location)
Import Count: 1 file (
pkg/console/spinner.go)Files Using SpinnerWrapper: 6 files across pkg/cli/
Research Findings
Recent Updates
The spinner module has been actively maintained with important recent improvements:
v1.23.2 (January 20, 2025) - Current version! 🎉
v1.23.1 (June 2024) - Security & Dependency Improvements
github.com/mattn/go-isattytogolang.org/x/termv1.22.0 (February 2023)
v1.21.0 (February 2023)
Best Practices from Maintainers
Recommended Usage Patterns
Use stderr for CLI tools:
This allows piping/redirecting output without spinner interference.
Add final messages:
Provides clear completion feedback to users.
Let library handle TTY detection:
The library has built-in TTY detection when using
WithWriter(), so manual checks may be redundant.Use dynamic updates for progress:
Improvement Opportunities
🏃 Quick Wins
1. Remove Redundant go-isatty Dependency
Impact: ⭐⭐⭐ (Immediate dependency reduction)
Issue: gh-aw uses
github.com/mattn/go-isattyfor TTY detection, but as of spinner v1.23.1, the library itself switched togolang.org/x/term.Benefit:
Location:
pkg/console/spinner.go:7-8Change:
2. Use Writer Configuration Instead of Manual TTY Check
Impact: ⭐⭐ (Code simplification)
Issue: SpinnerWrapper manually checks TTY and conditionally creates spinner.
Opportunity: Spinner library handles TTY detection internally with the
WithWriter()functional option.Benefit: Cleaner code, leverage library's built-in TTY detection logic.
✨ Feature Opportunities
3. Add Final Messages on Completion
Impact: ⭐⭐⭐⭐ (Significantly improves UX)
Feature: Use the
FinalMSGproperty to show success/completion messages when operations finish.Benefit: Clear visual feedback that operations completed successfully.
Examples:
Implementation: Add to SpinnerWrapper:
Impact: Improves UX across all 9 spinner usage locations!
4. Leverage Writer Control for Better Output Redirection
Impact: ⭐⭐⭐ (Improves pipeline compatibility)
Feature: Configure spinner to write to
os.Stderrinstead ofos.Stdout.Benefit:
Best Practice: Progress indicators should go to stderr, actual output to stdout.
Example:
5. Use Progress Indicators with Dynamic Updates
Impact: ⭐⭐⭐ (Better user experience)
Current State: Only
listWorkflowRunsWithPaginationupdates messages dynamically.Opportunity: Use
UpdateMessage()in more locations to show progress:Locations:
downloadRunArtifacts,cancelWorkflowRuns,getLatestWorkflowRunWithRetry📐 Best Practice Alignment
6. Consistent Error Handling for Color Setting
Impact: ⭐ (Better debugging)
Current:
_ = s.spinner.Color("cyan")ignores errors.Improvement: While ignoring is acceptable (fallback to default works), consider:
7. Consider Disable/Enable Toggle API
Impact: ⭐ (Optional refinement)
Feature: v1.19.0+ added
Enable()andDisable()methods.Current: SpinnerWrapper uses boolean flag and nil checks.
Trade-off: Current approach works well; this is an optional refinement for code clarity.
🔧 General Improvements
8. Centralize Spinner Configuration
Impact: ⭐⭐ (Customization flexibility)
Observation: All spinners use same configuration:
Opportunity: Make these configurable via environment variables or config file:
Benefit: Allow users to customize spinner appearance to their preference.
9. Add Context-Aware Spinner Messages
Impact: ⭐⭐ (Better feedback)
Current: Most messages are static strings.
Opportunity: Include more operational context:
10. Consider Spinner Character Set Variations
Impact: ⭐ (Visual polish)
Current: Always uses CharSet[14] (braille dots).
Opportunity: Use different character sets for different operation types:
Recommendations
Priority 1: Remove go-isatty Dependency ⚡
Effort: Low | Impact: High | Risk: Low
The spinner library moved away from go-isatty in v1.23.1. We should follow suit!
Action: Update
pkg/console/spinner.goto either:golang.org/x/term.IsTerminal()directly (matches spinner's approach)WithWriter(os.Stderr)optionWhy now: Already on v1.23.2, this aligns with current best practices.
Priority 2: Add Final Messages ✨
Effort: Medium | Impact: Very High | Risk: Low
Add completion messages so users see clear success/error states.
Action: Extend SpinnerWrapper with
StopWithMessage()method and add success messages to all 9 usage locations.User Experience:
Priority 3: Use Stderr for Spinner Output 📝
Effort: Low | Impact: Medium | Risk: Low
Configure spinners to write to stderr for better pipeline compatibility.
Action: Add
spinner.WithWriter(os.Stderr)to spinner initialization.Benefit: Users can redirect output while still seeing progress in terminal.
Priority 4: Enhance Progress Feedback 📊
Effort: Medium-High | Impact: High | Risk: Low
Add dynamic progress updates to long-running operations.
Action: Use
UpdateMessage()to show:Next Steps
pkg/console/spinner.goto remove go-isatty dependencyStopWithMessage()methodWithWriter(os.Stderr)for better pipingModule summary saved to:
specs/mods/spinner.mdGenerated by: Go Fan 🐹
Review Date: 2025-11-29
Module Version: v1.23.2
Beta Was this translation helpful? Give feedback.
All reactions