From 7e5e76d56b5d99134ba53cf1fa657f36a8b84da5 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Sat, 13 Aug 2022 15:57:48 +0100 Subject: [PATCH] Readme clean up --- README.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e459f2..a6b0825 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # You spin me right round -Ysmrr is a simple multi-line spinner package for your terminal. +[![Go Reference](https://pkg.go.dev/badge/github.com/chelnak/ysmrr.svg)](https://pkg.go.dev/github.com/chelnak/ysmrr) [![Go Version](https://img.shields.io/github/go-mod/go-version/chelnak/ysmrr.svg)](https://github.com/chelnak/ysmrr) [![GoReportCard](https://goreportcard.com/badge/github.com/chelnak/ysmrr)](https://goreportcard.com/report/github.com/chelnak/ysmrr) + +You Spin Me Right Round (`ysmrr`) is a package that provides simple multi-line compatible spinners for Go applications. !["ysmrr - examples/advanced/main.go"](advanced-example.gif) @@ -12,7 +14,79 @@ go get -u github.com/chelnak/ysmrr ## Usage -``` go +### SpinnerManager + +A `SpinnerManager` is a collection of spinners that share a common configuration. + +They can be created as follows: + +```go +sm := ysmrr.NewSpinnerManager() +``` + +The `NewSpinnerManager` method also accepts multiple options. For example, you can change the animation and the color of the spinner: + +```go +sm := ysmrr.NewSpinnerManager( + ysmrr.WithAnimation(animations.Pipe), + ysmrr.WithSpinnerColor(colors.FgHiBlue), +) +``` + +A `SpinnerManager` is also responsible for starting and stopping a group of spinners. + +#### Starting a spinner group + +```go +sm.Start() +``` + +#### Stopping a spinner group + +```go +sm.Stop() +``` + +### Spinners + +`SpinnerManagers` are great but pretty useless on their own. You need to add at least one spinner. + +Adding a new spinner is as simple as using the `AddSpinner` method on a `SpinnerManager` instance. + +It expects a string that will be displayed as the initial message of a spinner. + +```go +spinner := sm.AddSpinner("Downloading...") +``` + +`AddSpinner` will return a spinner instance that you can use to control the spinner. + +#### Updating the message + +Thoughout the lifecycle of a spinner, you can update the message of the spinner. + +```go +spinner.UpdateMessage("Downloading...") +``` + +#### Spinner state + +A spinner can be set to either `Complete` or `Error` to indicate the current state of a task. + +```go +spinner.Complete() +``` + +```go +spinner.Error() +``` + +### Example + +To tie everything together, here is an example that shows how to build a +basic spinner app. + +```go // Create a new spinner manager sm := ysmrr.NewSpinnerManager() @@ -31,7 +105,7 @@ time.Sleep(2 * time.Second) sm.Stop() ``` -For example usage, check out the [examples](examples) directory for. +For more usage examples, check out the [examples](examples) directory. ## Inspiration