Coder Social home page Coder Social logo

yash-handa / spinner Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 1.97 MB

Platform independent Go module to print spinners on Terminal/ cmd

Home Page: https://pkg.go.dev/github.com/Yash-Handa/spinner?tab=doc

License: MIT License

Go 100.00%
golang go terminal cmdline cmd spinner loader color

spinner's Introduction

spinner

Codacy Badge Go Report Card codecov Go PkgGoDev Total alerts GitHub go.mod Go version of a Go module GitHub release

Platform independent Go module to print spinners on Terminal/ cmd

Overview / Features

  • Have 80+ spinners, Segregated into ASCII(id: 1-999) and Unicode(id >= 1000) spinners

  • Custom (user-defined) spinners

  • Support rich color rendering output for the spinners (in both 16bit colors and Hexcodes)

  • Colors compatible with Windows system.

  • Universal and Stable API method

  • Made with concurrency handling in mind

Documentation

Complete documentation of the API is hosted at pkg.go.dev

Spinners

Below Tables show spinners with their IDs. Use it as reference

ASCII Spinners (ID 1 to 999)

ID: 1 Inter: 80ms ID: 2 Inter: 140ms ID: 3 Inter: 100ms
ID: 1 Inter: 80ms ID: 2 Inter: 140ms ID: 3 Inter: 100ms
ID: 4 Inter: 100ms ID: 5 Inter: 120ms ID: 6 Inter: 120ms
ID: 4 Inter: 100ms ID: 5 Inter: 120ms ID: 6 Inter: 120ms
ID: 7 Inter: 100ms ID: 8 Inter: 120ms ID: 9 Inter: 100ms
ID: 7 Inter: 100ms ID: 8 Inter: 120ms ID: 9 Inter: 100ms
ID: 10 Inter: 80ms ID: 11 Inter: 80ms ID: 12 Inter: 200ms
ID: 10 Inter: 80ms ID: 11 Inter: 80ms ID: 12 Inter: 200ms
ID: 13 Inter: 120ms ID: 14 Inter: 80ms ID: 15 Inter: 120ms
ID: 13 Inter: 120ms ID: 14 Inter: 80ms ID: 15 Inter: 120ms
ID: 16 Inter: 100ms ID: 17 Inter: 80ms ID: 18 Inter: 180ms
ID: 16 Inter: 100ms ID: 17 Inter: 80ms ID: 18 Inter: 180ms
ID: 19 Inter: 150ms ID: 20 Inter: 120ms ID: 21 Inter: 100ms
ID: 19 Inter: 150ms ID: 20 Inter: 120ms ID: 21 Inter: 100ms
ID: 22 Inter: 100ms ID: 23 Inter: 100ms
ID: 22 Inter: 100ms ID: 23 Inter: 100ms

Unicode Spinners (ID >= 1000)

ID: 1000 Inter: 80ms ID: 1001 Inter: 80ms ID: 1002 Inter: 80ms
ID: 1000 Inter: 80ms ID: 1001 Inter: 80ms ID: 1002 Inter: 80ms
ID: 1003 Inter: 80ms ID: 1004 Inter: 100ms ID: 1005 Inter: 100ms
ID: 1003 Inter: 80ms ID: 1004 Inter: 100ms ID: 1005 Inter: 100ms
ID: 1006 Inter: 100ms ID: 1007 Inter: 80ms ID: 1008 Inter: 100ms
ID: 1006 Inter: 100ms ID: 1007 Inter: 80ms ID: 1008 Inter: 100ms
ID: 1009 Inter: 80ms ID: 1010 Inter: 140ms ID: 1011 Inter: 120ms
ID: 1009 Inter: 80ms ID: 1010 Inter: 140ms ID: 1011 Inter: 120ms
ID: 1012 Inter: 100ms ID: 1013 Inter: 200ms ID: 1014 Inter: 120ms
ID: 1012 Inter: 100ms ID: 1013 Inter: 200ms ID: 1014 Inter: 120ms
ID: 1015 Inter: 100ms ID: 1016 Inter: 180ms ID: 1017 Inter: 120ms
ID: 1015 Inter: 100ms ID: 1016 Inter: 180ms ID: 1017 Inter: 120ms
ID: 1018 Inter: 120ms ID: 1019 Inter: 100ms ID: 1020 Inter: 80ms
ID: 1018 Inter: 120ms ID: 1019 Inter: 100ms ID: 1020 Inter: 80ms
ID: 1021 Inter: 80ms ID: 1022 Inter: 80ms ID: 1023 Inter: 80ms
ID: 1021 Inter: 80ms ID: 1022 Inter: 80ms ID: 1023 Inter: 80ms
ID: 1024 Inter: 80ms ID: 1025 Inter: 100ms ID: 1026 Inter: 80ms
ID: 1024 Inter: 80ms ID: 1025 Inter: 100ms ID: 1026 Inter: 80ms
ID: 1027 Inter: 80ms ID: 1028 Inter: 80ms ID: 1029 Inter: 80ms
ID: 1027 Inter: 80ms ID: 1028 Inter: 80ms ID: 1029 Inter: 80ms
ID: 1030 Inter: 100ms ID: 1031 Inter: 200ms ID: 1032 Inter: 100ms
ID: 1030 Inter: 100ms ID: 1031 Inter: 200ms ID: 1032 Inter: 100ms
ID: 1033 Inter: 100ms ID: 1034 Inter: 180ms ID: 1035 Inter: 150ms
ID: 1033 Inter: 100ms ID: 1034 Inter: 180ms ID: 1035 Inter: 150ms
ID: 1036 Inter: 120ms ID: 1037 Inter: 120ms ID: 1038 Inter: 180ms
ID: 1036 Inter: 120ms ID: 1037 Inter: 120ms ID: 1038 Inter: 180ms
ID: 1039 Inter: 180ms ID: 1040 Inter: 180ms ID: 1041 Inter: 180ms
ID: 1039 Inter: 180ms ID: 1040 Inter: 180ms ID: 1041 Inter: 180ms
ID: 1042 Inter: 150ms ID: 1043 Inter: 150ms ID: 1044 Inter: 150ms
ID: 1042 Inter: 150ms ID: 1043 Inter: 150ms ID: 1044 Inter: 150ms
ID: 1045 Inter: 150ms ID: 1046 Inter: 140ms ID: 1047 Inter: 150ms
ID: 1045 Inter: 150ms ID: 1046 Inter: 140ms ID: 1047 Inter: 150ms
ID: 1048 Inter: 150ms ID: 1049 Inter: 120ms ID: 1050 Inter: 150ms
ID: 1048 Inter: 150ms ID: 1049 Inter: 120ms ID: 1050 Inter: 150ms
ID: 1051 Inter: 120ms ID: 1052 Inter: 150ms ID: 1053 Inter: 100ms
ID: 1051 Inter: 120ms ID: 1052 Inter: 150ms ID: 1053 Inter: 100ms
ID: 1054 Inter: 100ms ID: 1055 Inter: 100ms ID: 1056 Inter: 100ms
ID: 1054 Inter: 100ms ID: 1055 Inter: 100ms ID: 1056 Inter: 100ms
ID: 1057 Inter: 200ms ID: 1058 Inter: 180ms
ID: 1057 Inter: 200ms ID: 1058 Inter: 180ms

Working Examples

These are simple examples. For more Indepth uses refer the API documentation hosted at pkg.go.dev

New Spinner

The following code creates a new spinner and uses it

package main

import (
  "time"
  "log"

 spinner "github.com/Yash-Handa/spinner"
)

func main() {
  sp, err := spinner.New(4, 50 * time.Millisecond, spinner.Cyan, spinner.Normal)
  if err != nil {
    log.Fatal(err)
  }

  sp.SetPostText("  Loading Content")
  sp.SetDoneText("Hurray spinner worked\n")

  sp.Start()                       // the spinner starts
  time.Sleep(3 * time.Second)      // after 3 seconds
  sp.SetColor(spinner.Magenta, "") // use previous background color
  sp.SetInterval(100 * time.Millisecond)
  sp.SetPostText("  The color and speed Changed !!")
  time.Sleep(3 * time.Second)
  sp.Stop() // the spinner stops
}



New Spinner


Custom Spinner

The following code creates a custom spinner using user defined symbols.

package main

import (
  "time"
  "log"

  spinner "github.com/Yash-Handa/spinner"
)

func main() {
  symbols := []string{"N   ", "IN  ", "PIN ", "SPIN", " SPI", "  SP", "   S", "    "}
  sp, err := spinner.Custom(symbols, 0, spinner.Red, spinner.Normal)
  if err != nil {
    log.Fatal(err)
  }

  sp.SetPostText("  A custom spinner")

  sp.Start()                  // the spinner starts
  time.Sleep(3 * time.Second) // after 3 seconds the color changes to lime green
  sp.SetColor("00e600", spinner.HexBgNormal)
  // spinner.HexBgNormal is used with Hex foreground to indicate that no background color to be used
  sp.SetPostText("  The color Changed !!")
  time.Sleep(3 * time.Second)
  sp.Stop() // the spinner stops
}



Custom Spinner


Contributions

The Project is Open Sourced under MIT License and will always welcomes Pull Request. Please read CONTRIBUTING.md.

spinner's People

Contributors

codacy-badger avatar yash-handa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

neo-godlike

spinner's Issues

would be nice to have spinner.Pause()

For those times when you want to show activity pausing. Should still support pre/post text update, though. I would imagine something like

sp.Pause() // would display first frame if not started. sp.Pause() twice is a no-op.
for i := 0; i<5; i++ {
     sp.SetPostText(fmt.Sprintf("paused for %d seconds"))
}
sp.Start()

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.