Code Monkey home page Code Monkey logo

go-spinner's Introduction

Simple CLI Spinner for Go

This is a simple spinner / activity indicator for Go command line apps. Useful when you want your users to know that there is activity and that the program isn't hung.
The indicator automagically converts itself in a simple log message if it detects that you have piped stdout to somewhere else than the console (You don't really want a spinner in your logger, do you?).

asciicast

Installation

To install spinner.go, simply run:

$ go get github.com/janeczku/go-spinner

Make sure your PATH includes to the $GOPATH/bin directory so your commands can be easily used:

export PATH=$PATH:$GOPATH/bin

Example usage

package main

import (
	"time"
	"github.com/janeczku/go-spinner"
	
)

func main() {
	s := spinner.StartNew("This may take some while...")
	time.Sleep(3 * time.Second) // something more productive here
	s.Stop()
}

API

s := spinner.StartNew(title string)

Quickstart. Creates a new spinner with default options and start it

s := spinner.NewSpinner(title string)

Creates a new spinner object

s.SetSpeed(time.Millisecond)

Sets a custom speed for the spinner animation (default 150ms/frame)

s.SetCharset([]string)

If you don't like the spinning stick, give it an Array of strings like {".", "o", "0", "@", "*"}

s.Start()

Start printing out the spinner animation

s.Stop()

Stops the spinner

go-spinner's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-spinner's Issues

IsTerminal check fails on Windows

Not that I actually need it myself right now, but I was cross-compiling my app for completeness and got this:

# github.com/janeczku/go-spinner
../../Projects/Go/pkg/mod/github.com/janeczku/[email protected]/spinner.go:39:25: cannot use syscall.Stdout (type syscall.Handle) as type int in argument to terminal.IsTerminal

Probably the simplest thing is either to assume that Windows is always a TTY, or never a TTY โ€” probably the latter since I'm guessing there will be other issues. An explicit type assertion on syscall.Stdout would probably take care of the compilation error; I can submit a PR if you think that makes sense.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.