spinner

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

README

godoc codecov Go Report Card

spinner - unicode character spinner

spinner implements a means of rendering unicode characters that give a sense that something is happening and that the user is waiting during that process.

Installation

> go get github.com/go-corelibs/spinner@latest

Examples

Spinner

func main() {
    // make a new Spinner with all the defaults and no func
    s := spinner.New(nil, nil)
    symbol := s.Symbol()
    // symbol == spinner.DefaultSymbols[0]
    s.Increment()
    // symbol == spinner.DefaultSymbols[1]
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2023 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package spinner implements a means of rendering unicode characters that give a sense that something is happening and that the user is waiting during that process.

The Spinner constructed does not actually write or otherwise output anything in particular. Instead, it simply provides the current unicode character for that moment or iteration depending on whether Spinner.Start was called or if the Spinner.Increment method is used to step to the next logical character in the loop.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSpinnerRunes, _ = paint.GetSpinners(paint.SevenDotSpinner)
	DefaultSymbols         = DefaultSpinnerRunes.Strings()
)

Functions

This section is empty.

Types

type Callback

type Callback func(symbol string)

Callback is the function signature for the `fn` argument to New

type Spinner

type Spinner interface {
	// String returns the current symbol
	String() (symbol string)
	// Increment moves the spinner to the symbol
	Increment()
	// Start simply calls StartWith an interval of 250ms
	Start()
	// StartWith (and Start) are blocking operations, use a goroutine
	// to start a spinner in the background. If using within a Go-Curses
	// environment, use cdk.Go to invoke the goroutine. Once started,
	// a time.Ticker is used to call the New `fn` (if not nil) and
	// increment the spinner state once every interval
	StartWith(interval time.Duration)
	// Stop stops any started incrementing
	Stop()
}

Spinner is the interface for interacting with the New Spinner instance, all methods are concurrency safe

func New

func New(symbols []string, fn Callback) (s Spinner)

New constructs a new Spinner instance

Jump to

Keyboard shortcuts

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