https://github.com/ianfoo/txtspin
Text-based spinners for Go CLI programs
https://github.com/ianfoo/txtspin
cli go golang
Last synced: 5 months ago
JSON representation
Text-based spinners for Go CLI programs
- Host: GitHub
- URL: https://github.com/ianfoo/txtspin
- Owner: ianfoo
- License: mit
- Created: 2020-04-27T14:42:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-27T20:33:57.000Z (about 6 years ago)
- Last Synced: 2024-06-20T05:03:01.155Z (about 2 years ago)
- Topics: cli, go, golang
- Language: Go
- Homepage:
- Size: 132 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# txtspin
A little Go package that adds a spinner and an optional message to
tasks that may take a minute to run.
A number of default Spinners are defined, or you can create one with a slice of
strings as the frames of the animation. Run `example/example.go` to see a quick
demo of the defined styles, or experiment with different patterns and speeds.
[](https://asciinema.org/a/EESP65f2tk9vlF1LQcxdhSDm3)
### Tip
For best flexibility, the `Spinner` function takes a function that takes takes
no parameters and returns nothing. If the operation you want to call takes
arguments, or returns values, just wrap it in a small function that closes over
values that you can inspect after the operation has finished.
```
var (
err error
result Result
f = func() { result, err = MyPossiblyErroringOperation(arg) }
spinner = txtspin.New(txtspin.StyleDefault)
)
spinner(f, "running slow op!")
```
### Caveats
This should only be used if it's known that the output is bound for a TTY.
You can use [go-isatty](https://github.com/mattn/go-isatty) to determine
this.
This was written for fun late one night and carries the commensurate
guarantees of stability and well-testedness.