progress

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: MIT Imports: 5 Imported by: 1

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":        {" ", "="},
	"double-":       {" ", "-", "="},
	"single":        {" ", "-"},
	"parallelogram": {"▱", "▰"},
	"spaced-blocks": {"▯", "▮"},
	"block":         {" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"},
	"blocky":        {" ", "▖", "▌", "▛", "█"},
	"block-gray":    {"▒", "█"},
	"braille":       {"⠀", "⠁", "⠃", "⠇", "⡇", "⣇", "⣧", "⣷", "⣿"},
	"line":          {"─", "╾", "━"},
	"":              {" ", "="},
}

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 interface{}) (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 interface{}) (result string)

GetBar returns the string that represents the progressbar in the set style for the given progress. If the parameters are not numeric, the percentage will be 0

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