busyIndicator

package module
v0.0.0-...-5f77824 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2015 License: MIT Imports: 9 Imported by: 0

README

busyIndicator

Build Status License

This is mostly a for-fun project as an excuse to mess with some things I don't normally have a reason to use. There are other similar projects that may be more mature.

-- import "github.com/ckaznocha/busyIndicator"

Usage

var (

	//Spin is a standard spinner
	Spin = []string{"-", "\\", "|", "/"}

	//Dot is an ellipsis sequence
	Dot = []string{"", ".", "..", "..."}

	//Grow is a . that grows up to be an O
	Grow = []string{".", "ₒ", "ⱺ", "O", "ⱺ", "ₒ", "."}
)
func Progress
func Progress(
	marks ProgressMarks,
	progress chan float64,
	cancel chan bool,
)

Progress starts a progress bar

func ProgressAnimated
func ProgressAnimated(
	marks ProgressMarks,
	speed time.Duration,
	progress chan float64,
	cancel chan bool,
)

ProgressAnimated starts an animated progress bar

func Throbber
func Throbber(
	vals []string,
	speed time.Duration,
	c chan bool,
)

Throbber starts a throbber

func ThrobberPostfixed
func ThrobberPostfixed(
	postfix string,
	vals []string,
	speed time.Duration,
	c chan bool,
)

ThrobberPostfixed starts a throbber with a given static postfix

func ThrobberPrefixed
func ThrobberPrefixed(
	prefix string,
	vals []string,
	speed time.Duration,
	c chan bool,
)

ThrobberPrefixed starts a throbber with a given static prefix

func ThrobberPrefixedAndPostfixed
func ThrobberPrefixedAndPostfixed(
	prefix string,
	postfix string,
	vals []string,
	speed time.Duration,
	c chan bool,
)

ThrobberPrefixedAndPostfixed starts a throbber with a given static prefix and postfix

type ProgressMarks
type ProgressMarks struct {
	Completed  rune
	Incomplete rune
}

ProgressMarks holds the runes you'd like to use for your progress bar

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (

	//Spin is a standard spinner
	Spin = []string{"-", "\\", "|", "/"}

	//Dot is an ellipsis sequence
	Dot = []string{"", ".", "..", "..."}

	//Grow is a . that grows up to be an O
	Grow = []string{".", "ₒ", "ⱺ", "O", "ⱺ", "ₒ", "."}
)

Functions

func Progress

func Progress(
	marks ProgressMarks,
	progress chan float64,
	cancel chan bool,
)

Progress starts a progress bar

func ProgressAnimated

func ProgressAnimated(
	marks ProgressMarks,
	speed time.Duration,
	progress chan float64,
	cancel chan bool,
)

ProgressAnimated starts an animated progress bar

Example
package main

import (
	"testing"
	"time"

	"github.com/ckaznocha/busyIndicator"
)

func main(t *testing.T) {
	var (
		i float64
		c = make(chan bool)
		p = make(chan float64)
	)
	defer close(c)
	defer close(p)
	go busyIndicator.Progress(busyIndicator.ProgressMarks{'#', '~'}, p, c)

	for i < 1 {
		p <- i
		i += 0.10
		time.Sleep(1 * time.Second)
	}
	c <- true
}
func main() {
	var (
		i float64
		c = make(chan bool)
		p = make(chan float64)
	)
	defer close(c)
	defer close(p)
	go busyIndicator.ProgressAnimated(
		busyIndicator.ProgressMarks{'=', '-'},
		100*time.Millisecond,
		p,
		c,
	)

	for i < 1 {
		p <- i
		i += 0.10
		time.Sleep(2 * time.Second)
	}
	c <- true
}
Output:

func Throbber

func Throbber(
	vals []string,
	speed time.Duration,
	c chan bool,
)

Throbber starts a throbber

Example
package main

import (
	"time"

	"github.com/ckaznocha/busyIndicator"
)

func main() {
	c := make(chan bool)

	go busyIndicator.Throbber(busyIndicator.Spin, 50*time.Millisecond, c)
	time.Sleep(1 * time.Second)
	c <- true

	go busyIndicator.Throbber(busyIndicator.Dot, 100*time.Millisecond, c)
	time.Sleep(1 * time.Second)
	c <- true

	go busyIndicator.Throbber(busyIndicator.Grow, 150*time.Millisecond, c)
	time.Sleep(10 * time.Second)
	c <- true
}
Output:

func ThrobberPostfixed

func ThrobberPostfixed(
	postfix string,
	vals []string,
	speed time.Duration,
	c chan bool,
)

ThrobberPostfixed starts a throbber with a given static postfix

func ThrobberPrefixed

func ThrobberPrefixed(
	prefix string,
	vals []string,
	speed time.Duration,
	c chan bool,
)

ThrobberPrefixed starts a throbber with a given static prefix

Example
package main

import (
	"time"

	"github.com/ckaznocha/busyIndicator"
)

func main() {
	c := make(chan bool)

	go busyIndicator.ThrobberPrefixed("hello ", busyIndicator.Spin, 100*time.Millisecond, c)
	time.Sleep(1 * time.Second)
	c <- true
}
Output:

func ThrobberPrefixedAndPostfixed

func ThrobberPrefixedAndPostfixed(
	prefix string,
	postfix string,
	vals []string,
	speed time.Duration,
	c chan bool,
)

ThrobberPrefixedAndPostfixed starts a throbber with a given static prefix and postfix

Types

type ProgressMarks

type ProgressMarks struct {
	Completed  rune
	Incomplete rune
}

ProgressMarks holds the runes you'd like to use for your progress bar

Jump to

Keyboard shortcuts

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