package progress

import "git.sr.ht/~poldi1405/go-indicators/progress"

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

Code:

{
	var p Progress
	p.GetBar(275, 346)
}
Example (CustomStyle)

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

Code:

{
	var p Progress

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

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

Code:

{
	var p Progress
	p.SetStyle("parallelogram")
	p.GetBar(275, 346)
}

Index

Examples

Variables

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

Source Files

calculate.go doc.go styles.go type.go

Version
v1.2.0 (latest)
Published
Apr 16, 2023
Platform
linux/amd64
Imports
5 packages
Last checked
2 weeks ago

Tools for package owners.