progress

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 4 Imported by: 9

Documentation

Overview

Package progress allows to easily create a progressbar by simply providing the total and the completed parts.

Example

The easiest way to get a progressbar is as follows

var p Progress
p.GetBar(275, 346)
Output:

Example (CustomStyle)

Using a custom style is as simple as adding it and changing to it

var p Progress

DefineStyle("my-style", []string{"○", "◔", "◑", "◕", "●"})
p.SetStyle("my-style")
p.GetBar(275, 346)
Output:

Example (Styled)

Changing the Style is not hard, in fact it's quite easy

var p Progress
p.SetStyle("parallelogram")
p.GetBar(275, 346)
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ProgressStyles = map[string][]string{
	"double":        []string{" ", "="},
	"double-":       []string{" ", "-", "="},
	"single":        []string{" ", "-"},
	"parallelogram": []string{"▱", "▰"},
	"spaced-blocks": []string{"▯", "▮"},
	"block":         []string{" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"},
	"":              []string{" ", "="},
}

ProgressStyles contains the styles of the progressbars. Custom styles can easily be appended and used.

Functions

func DefineStyle

func DefineStyle(name string, characters []string)

DefineStyle allows registering a custom progress-style to use. If the name is already defined it is overwritten. Directly defining it is possible but not recommended.

func GetPercentage

func GetPercentage(parts, total float64) (float64, error)

GetPercentage returns the percentage of a part from a total.

Types

type Progress

type Progress struct {
	Width int
	// contains filtered or unexported fields
}

Progress contains the settings of a Progressbar.

func (*Progress) GetBar

func (p *Progress) GetBar(parts, total float64) (result string)

GetBar returns the string that represents the progressbar in the set style for the given progress

func (*Progress) SetStyle

func (p *Progress) SetStyle(style string)

SetStyle sets the style that should be used with the progressbar

Jump to

Keyboard shortcuts

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