spinner

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2020 License: MIT Imports: 6 Imported by: 0

README

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: 4 Inter: 100ms ID: 5 Inter: 120ms ID: 6 Inter: 120ms
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: 13 Inter: 120ms ID: 14 Inter: 80ms ID: 15 Inter: 120ms
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: 22 Inter: 100ms ID: 23 Inter: 100ms
Unicode Spinners (ID >= 1000)
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: 1006 Inter: 100ms ID: 1007 Inter: 80ms ID: 1008 Inter: 100ms
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: 1015 Inter: 100ms ID: 1016 Inter: 180ms ID: 1017 Inter: 120ms
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: 1024 Inter: 80ms ID: 1025 Inter: 100ms ID: 1026 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: 1033 Inter: 100ms ID: 1034 Inter: 180ms ID: 1035 Inter: 150ms
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: 1042 Inter: 150ms ID: 1043 Inter: 150ms ID: 1044 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: 1051 Inter: 120ms ID: 1052 Inter: 150ms ID: 1053 Inter: 100ms
ID: 1054 Inter: 100ms ID: 1055 Inter: 100ms ID: 1056 Inter: 100ms
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.

Documentation

Overview

Package spinner is Command line spinner library.

Have 80+ spinners, Segregated into ASCII(id: 1-999) and Unicode(id >= 1000) spinners and even custom (user-defined) spinners !!!

Support rich color rendering output for the spinners (in both 16bit colors and Hexcodes), universal API method, compatible with Windows system.

Made with concurrency handling in mind.

Source code and other details for the project are available at GitHub:

https://github.com/Yash-Handa/spinner

More usage please see README and tests.

Index

Constants

View Source
const (
	Red     = "Red"
	Black   = "Black"
	Green   = "Green"
	Yellow  = "Yellow"
	Blue    = "Blue"
	Magenta = "Magenta"
	Cyan    = "Cyan"
	White   = "White"
	Normal  = "Normal" // Normal represents No color

)

Supported 16-bit colors, these are the most supported colors and will render on any version of cmd/ powershell. These can be used as both forground and background colors.

View Source
const HexBgNormal = "HexBgNormal"

HexBgNormal is a special color that sets background for HexColor forground to nothing. Basically a spinner with only Hex (256) code forground color

Variables

View Source
var SpinnerMap = map[uint][]string{
	1:  {"|", "/", "-", "\\"},
	2:  {"[   ]", "[=  ]", "[ = ]", "[  =]"},
	3:  {"[=   ]", "[==  ]", "[ == ]", "[  ==]", "[   =]"},
	4:  {"[    ]", "[#   ]", "[##  ]", "[### ]", "[####]", "[ ###]", "[  ##]", "[   #]"},
	5:  {"   ", ".  ", ".. ", "..."},
	6:  {"   ", ".  ", ".. ", "...", " ..", "  ."},
	7:  {"[    ]", "[=   ]", "[==  ]", "[=== ]", "[====]"},
	8:  {"(-*--)", "(--*-)", "(---*)", "(--*-)", "(-*--)", "(*---)"},
	9:  {"( *  )", "(  * )", "(   *)", "(  * )", "( *  )", "(*   )"},
	10: {"|   ", "||  ", "||| ", "||||", " |||", "  ||", "   |"},
	11: {">))'>    ", " >))'>   ", "  >))'>  ", "   >))'> ", "    >))'>", "   <'((< ", "  <'((<  ", " <'((<   "},
	12: {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"},
	13: {".", "o", "O", "'", "O", "o", "."},
	14: {"+", "x"},
	15: {"v", "<", "^", ">"},
	16: {">>--->    ", " >>--->   ", "  >>--->  ", "   >>---> ", "    >>--->", "    <---<<", "   <---<< ", "  <---<<  ", " <---<<   ", "<---<<    "},
	17: {"  . . . .", ".   . . .", ". .   . .", ". . .   .", ". . . .  ", ". . . . ."},
	18: {" ....", ". ...", ".. ..", "... .", ".... ", "....."},
	19: {" |     ", "  /    ", "   _   ", `    \  `, "     | ", `    \  `, "   _   ", "  /    "},
	20: {"[    ]", "[   =]", "[  ==]", "[ ===]", "[====]", "[=== ]", "[==  ]", "[=   ]"},
	21: {"[|\\__________]", "[_|\\_________]", "[__|\\________]", "[___|\\_______]", "[____|\\______]", "[_____|\\_____]", "[______|\\____]", "[_______|\\___]", "[________|\\__]", "[_________|\\_]", "[__________|\\]", "[__________/|]", "[_________/|_]", "[________/|__]", "[_______/|___]", "[______/|____]", "[_____/|_____]", "[____/|______]", "[___/|_______]", "[__/|________]", "[_/|_________]", "[/|__________]"},
	22: {"d", "q", "p", "b"},
	23: {".", "o", "O", "@", "*"},

	1000: {"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"},
	1001: {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▁"},
	1002: {"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"},
	1003: {"▖", "▘", "▝", "▗"},
	1004: {"┤", "┘", "┴", "└", "├", "┌", "┬", "┐"},
	1005: {"◢", "◣", "◤", "◥"},
	1006: {"◰", "◳", "◲", "◱"},
	1007: {"◴", "◷", "◶", "◵"},
	1008: {"◐", "◓", "◑", "◒"},
	1009: {"◡◡", "⊙⊙", "◠◠"},
	1010: {"🌍", "🌎", "🌏"},
	1011: {"◜ ", " ◝", " ◞", "◟ "},
	1012: {"⇐", "⇖", "⇑", "⇗", "⇒", "⇘", "⇓", "⇙"},
	1013: {"Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", "Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"},
	1014: {"■", "□", "▪", "▫"},
	1015: {"←", "↑", "→", "↓"},
	1016: {"╫", "╪"},
	1017: {"█▒▒▒▒▒▒▒▒▒", "███▒▒▒▒▒▒▒", "█████▒▒▒▒▒", "███████▒▒▒", "██████████"},
	1018: {"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"},
	1019: {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
	1020: {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"},
	1021: {"⠁", "⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈", "⠈"},
	1022: {"⠈", "⠉", "⠋", "⠓", "⠒", "⠐", "⠐", "⠒", "⠖", "⠦", "⠤", "⠠", "⠠", "⠤", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋", "⠉", "⠈"},
	1023: {"⠁", "⠉", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠤", "⠄", "⠄", "⠤", "⠴", "⠲", "⠒", "⠂", "⠂", "⠒", "⠚", "⠙", "⠉", "⠁"},
	1024: {"⠋", "⠙", "⠚", "⠒", "⠂", "⠂", "⠒", "⠲", "⠴", "⠦", "⠖", "⠒", "⠐", "⠐", "⠒", "⠓", "⠋"},
	1025: {"⢹", "⢺", "⢼", "⣸", "⣇", "⡧", "⡗", "⡏"},
	1026: {"⢄", "⢂", "⢁", "⡁", "⡈", "⡐", "⡠"},
	1027: {"⠀", "⠁", "⠂", "⠃", "⠄", "⠅", "⠆", "⠇", "⡀", "⡁", "⡂", "⡃", "⡄", "⡅", "⡆", "⡇", "⠈", "⠉", "⠊", "⠋", "⠌", "⠍", "⠎", "⠏", "⡈", "⡉", "⡊", "⡋", "⡌", "⡍", "⡎", "⡏", "⠐", "⠑", "⠒", "⠓", "⠔", "⠕", "⠖", "⠗", "⡐", "⡑", "⡒", "⡓", "⡔", "⡕", "⡖", "⡗", "⠘", "⠙", "⠚", "⠛", "⠜", "⠝", "⠞", "⠟", "⡘", "⡙", "⡚", "⡛", "⡜", "⡝", "⡞", "⡟", "⠠", "⠡", "⠢", "⠣", "⠤", "⠥", "⠦", "⠧", "⡠", "⡡", "⡢", "⡣", "⡤", "⡥", "⡦", "⡧", "⠨", "⠩", "⠪", "⠫", "⠬", "⠭", "⠮", "⠯", "⡨", "⡩", "⡪", "⡫", "⡬", "⡭", "⡮", "⡯", "⠰", "⠱", "⠲", "⠳", "⠴", "⠵", "⠶", "⠷", "⡰", "⡱", "⡲", "⡳", "⡴", "⡵", "⡶", "⡷", "⠸", "⠹", "⠺", "⠻", "⠼", "⠽", "⠾", "⠿", "⡸", "⡹", "⡺", "⡻", "⡼", "⡽", "⡾", "⡿", "⢀", "⢁", "⢂", "⢃", "⢄", "⢅", "⢆", "⢇", "⣀", "⣁", "⣂", "⣃", "⣄", "⣅", "⣆", "⣇", "⢈", "⢉", "⢊", "⢋", "⢌", "⢍", "⢎", "⢏", "⣈", "⣉", "⣊", "⣋", "⣌", "⣍", "⣎", "⣏", "⢐", "⢑", "⢒", "⢓", "⢔", "⢕", "⢖", "⢗", "⣐", "⣑", "⣒", "⣓", "⣔", "⣕", "⣖", "⣗", "⢘", "⢙", "⢚", "⢛", "⢜", "⢝", "⢞", "⢟", "⣘", "⣙", "⣚", "⣛", "⣜", "⣝", "⣞", "⣟", "⢠", "⢡", "⢢", "⢣", "⢤", "⢥", "⢦", "⢧", "⣠", "⣡", "⣢", "⣣", "⣤", "⣥", "⣦", "⣧", "⢨", "⢩", "⢪", "⢫", "⢬", "⢭", "⢮", "⢯", "⣨", "⣩", "⣪", "⣫", "⣬", "⣭", "⣮", "⣯", "⢰", "⢱", "⢲", "⢳", "⢴", "⢵", "⢶", "⢷", "⣰", "⣱", "⣲", "⣳", "⣴", "⣵", "⣶", "⣷", "⢸", "⢹", "⢺", "⢻", "⢼", "⢽", "⢾", "⢿", "⣸", "⣹", "⣺", "⣻", "⣼", "⣽", "⣾", "⣿"},
	1028: {"⢀⠀", "⡀⠀", "⠄⠀", "⢂⠀", "⡂⠀", "⠅⠀", "⢃⠀", "⡃⠀", "⠍⠀", "⢋⠀", "⡋⠀", "⠍⠁", "⢋⠁", "⡋⠁", "⠍⠉", "⠋⠉", "⠋⠉", "⠉⠙", "⠉⠙", "⠉⠩", "⠈⢙", "⠈⡙", "⢈⠩", "⡀⢙", "⠄⡙", "⢂⠩", "⡂⢘", "⠅⡘", "⢃⠨", "⡃⢐", "⠍⡐", "⢋⠠", "⡋⢀", "⠍⡁", "⢋⠁", "⡋⠁", "⠍⠉", "⠋⠉", "⠋⠉", "⠉⠙", "⠉⠙", "⠉⠩", "⠈⢙", "⠈⡙", "⠈⠩", "⠀⢙", "⠀⡙", "⠀⠩", "⠀⢘", "⠀⡘", "⠀⠨", "⠀⢐", "⠀⡐", "⠀⠠", "⠀⢀", "⠀⡀"},
	1029: {"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"},
	1030: {"⎺", "⎻", "⎼", "⎽", "⎼", "⎻"},
	1031: {"ヲ", "ァ", "ィ", "ゥ", "ェ", "ォ", "ャ", "ュ", "ョ", "ッ", "ア", "イ", "ウ", "エ", "オ", "カ", "キ", "ク", "ケ", "コ", "サ", "シ", "ス", "セ", "ソ", "タ", "チ", "ツ", "テ", "ト", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "ヒ", "フ", "ヘ", "ホ", "マ", "ミ", "ム", "メ", "モ", "ヤ", "ユ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ワ", "ン"},
	1032: {"(●    )", "( ●   )", "(  ●  )", "(   ● )", "(    ●)", "(   ● )", "(  ●  )", "( ●   )", "(●    )"},
	1033: {"✶", "✸", "✹", "✺", "✹", "✷"},
	1034: {"¿", "?"},
	1035: {"▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"},
	1036: {"⬒", "⬔", "⬓", "⬕"},
	1037: {".", "o", "O", "°", "O", "o", "."},
	1038: {"▓", "▒", "░"},
	1039: {"▌", "▀", "▐", "▄"},
	1040: {"⊶", "⊷"},
	1041: {"▪", "▫"},
	1042: {"□", "■"},
	1043: {"▮", "▯"},
	1044: {"-", "=", "≡"},
	1045: {"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"},
	1046: {"🌑 ", "🌒 ", "🌓 ", "🌔 ", "🌕 ", "🌖 ", "🌗 ", "🌘 "},
	1047: {"☗", "☖"},
	1048: {"⧇", "⧆"},
	1049: {"◉", "◎"},
	1050: {"㊂", "㊀", "㊁"},
	1051: {"⦾", "⦿"},
	1052: {"▌ ", "▀ ", "▐▄"},
	1053: {"▐|\\__________▌", "▐_|\\_________▌", "▐__|\\________▌", "▐___|\\_______▌", "▐____|\\______▌", "▐_____|\\_____▌", "▐______|\\____▌", "▐_______|\\___▌", "▐________|\\__▌", "▐_________|\\_▌", "▐__________|\\▌", "▐__________/|▌", "▐_________/|_▌", "▐________/|__▌", "▐_______/|___▌", "▐______/|____▌", "▐_____/|_____▌", "▐____/|______▌", "▐___/|_______▌", "▐__/|________▌", "▐_/|_________▌", "▐/|__________▌"},
	1054: {"▐⠂       ▌", "▐⠈       ▌", "▐ ⠂      ▌", "▐ ⠠      ▌", "▐  ⡀     ▌", "▐  ⠠     ▌", "▐   ⠂    ▌", "▐   ⠈    ▌", "▐    ⠂   ▌", "▐    ⠠   ▌", "▐     ⡀  ▌", "▐     ⠠  ▌", "▐      ⠂ ▌", "▐      ⠈ ▌", "▐       ⠂▌", "▐       ⠠▌", "▐       ⡀▌", "▐      ⠠ ▌", "▐      ⠂ ▌", "▐     ⠈  ▌", "▐     ⠂  ▌", "▐    ⠠   ▌", "▐    ⡀   ▌", "▐   ⠠    ▌", "▐   ⠂    ▌", "▐  ⠈     ▌", "▐  ⠂     ▌", "▐ ⠠      ▌", "▐ ⡀      ▌", "▐⠠       ▌"},
	1055: {"◇", "◈", "◆"},
	1056: {"⬖", "⬘", "⬗", "⬙"},
	1057: {"♠", "♣", "♥", "♦"},
	1058: {"➞", "➟", "➠", "➡", "➠", "➟"},
}

SpinnerMap maps spinner IDs to spinner symbols. No real use-case other than inspiration and documentation

Functions

func Random16BitColor added in v0.1.2

func Random16BitColor() string

Random16BitColor returns the string representation of a random 16 Bit color

func RandomHexColor added in v0.1.2

func RandomHexColor() string

RandomHexColor return the string representation of the hex code ("#rrggbb") of a a random color

Types

type Spinner

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner type represents the spinner itself. Note it does not export anything, Use getters and setters on this type to manipulate the spinner.

func Custom added in v1.1.0

func Custom(symbols []string, interval time.Duration, forground, background string) (*Spinner, error)

Custom creates a new spinner based on user defined symbols (a slice of strings).

Parameters:

symbols : it is slice of stings used to produce a spinner. All strings in the
          slice should be of same size or an error will be returned

interval: it is of type time.Duration and sets the refresh rate of the spinner
          (the time frame after which spinner will be updated). If 0 is
          provided the default value of 100 * time.Millisecond will be

forground: it could be a 16-Bit type (16-bit colors are defined as constants at
           the starting of the package like spinner.Red, etc) or Hex type
           (strings like "00e600", "#00E600", "ccc", etc). Empty string will
           use spinner.Normal

background: it could be a 16-Bit type (16-bit colors are defined as constants
            at the starting of the package like spinner.Red, etc) or Hex type
            (strings like "00e600", "#00E600", "ccc", etc). Empty string will
            use spinner.Normal

Note- forground and background should be of the same form either both will be
16-bit colors or both will be hex. Not a combination. In case of any error in
resolving colors both forground and background will use spinner.Normal

Example:

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 forground to indicate that no background color to be used
	sp.SetPostText("  The color Changed !!")
	time.Sleep(3 * time.Second)
	sp.Stop() // the spinner stops
}

all custom spinners have ID of 0

func New

func New(id uint, interval time.Duration, forground, background string) (*Spinner, error)

New creates a new spinner based on the ID provided.

Parameters:

id: it is a uint mapped a pre-defined spinners.
    If the id is invalid an error will occur
    id from 1 to 999 represent ASCII spinners (supported on all terminals)
    id >= 1000 represent Unicode point spinners (supported by terminals which
    are UTF-8 encoded)

interval: it is of type time.Duration and sets the refresh rate of the spinner
          (the time frame after which spinner will be updated). If 0 is
          provided the default value of 100 * time.Millisecond will be

forground: it could be a 16-Bit type (16-bit colors are defined as constants at
           the starting of the package like spinner.Red, etc) or Hex type
           (strings like "00e600", "#00E600", "ccc", etc). Empty string will
           use spinner.Normal

background: it could be a 16-Bit type (16-bit colors are defined as constants
            at the starting of the package like spinner.Red, etc) or Hex type
            (strings like "00e600", "#00E600", "ccc", etc). Empty string will
            use spinner.Normal

Note- forground and background should be of the same form either both will be
16-bit colors or both will be hex. Not a combination. In case of any error in
resolving colors both forground and background will use spinner.Normal

Example:

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
}

func (*Spinner) GetDoneText added in v0.2.0

func (s *Spinner) GetDoneText() string

GetDoneText returns the current value of the text which will be printed after the spinner has been stopped, by calling stop() method on spinner variable

func (*Spinner) GetID

func (s *Spinner) GetID() uint

GetID returns the ID of a spinner.

Note:

If a spinner is ASCII based its ID will be from 1 to 999.
If a spinner is Unicode based then its ID will be >= 1000.
For custom/ user-defined spinners the ID is 0.

func (*Spinner) GetInterval

func (s *Spinner) GetInterval() time.Duration

GetInterval returns the interval of the spinner

func (*Spinner) GetPostText added in v0.2.0

func (s *Spinner) GetPostText() string

GetPostText returns the current value of the text which will be printed after the spinner

func (*Spinner) GetPreText added in v0.2.0

func (s *Spinner) GetPreText() string

GetPreText returns the current value of the text which will be printed before the spinner

func (*Spinner) IsSpinning

func (s *Spinner) IsSpinning() bool

IsSpinning returns true if the spinner is active i.e., started() has been called but the corresponding stop() method hasn't

func (*Spinner) Restart added in v0.2.0

func (s *Spinner) Restart()

Restart stops the spinner (if not stopped already) and then restarts it.

func (*Spinner) SetColor added in v0.2.0

func (s *Spinner) SetColor(forground, background string)

SetColor sets the forground and background of a spinner. It can be called any number of time to update the colors.

Default: The default value or zero values are forground = spinner.Normal and background = spinner.Normal. Incase of any erroneous value these defaults are used.

Note:

i. Both the forground and background should be either of 16-Bit type (Constants are defined at the starting of the package like spinner.Red, etc) or Hex type (like "00e600", "#00E600", "ccc", etc) but not a combination of both

ii. If an empty string is provided as the value of background then the priviously used background value is used

func (*Spinner) SetDoneText added in v0.2.0

func (s *Spinner) SetDoneText(done string)

SetDoneText takes a string that will be printed after the spinners has stopped spinning.

func (*Spinner) SetInterval added in v0.2.0

func (s *Spinner) SetInterval(t time.Duration)

SetInterval takes a parameter of time.Duration type and sets the interval / refersh rate of the spinner to it. It can be called any number of time to update the interval value.

the spinner symbol, pre-text and post-text are all refreshed at each interval duraton

Default: The default value or zero value is 100 * time.Millisecond

func (*Spinner) SetPostText added in v0.2.0

func (s *Spinner) SetPostText(post string)

SetPostText takes a string that will be printed after the spinner.

SetPostText can be called multiple time during the life-time of the spinner to change the string value (default is an empty string). The spinner will check and print the value of the value of this pre-text at each interval duration (refresh time of the spinner)

Note: any leading or trialing newlines ('\n', '\r\n') will be trimmed

func (*Spinner) SetPreText added in v0.2.0

func (s *Spinner) SetPreText(pre string)

SetPreText takes a string that will be printed before the spinner.

SetPreText can be called multiple time during the life-time of the spinner to change the string value (default is an empty string). The spinner will check and print the value of the value of this pre-text at each interval duration (refresh time of the spinner)

Note: any leading or trialing newlines ('\n', '\r\n') will be trimmed

func (*Spinner) Start

func (s *Spinner) Start()

Start starts the spinner. It is concurrency safe. Start can be called multiple times even on an already started spinner without any problem

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops a spinner. It is concurrency safe. Stop can be called multiple times even on an already stopped spinner without any problem

Jump to

Keyboard shortcuts

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