bar

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package bar provides functionality for progress bar rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BType

type BType uint

BType represents kind of progress bar.

const (
	// BTypeUnknown is a default empty value for unknown progress bar type.
	BTypeUnknown BType = iota

	// BTypeRendered is a progress bar that will be rendered.
	BTypeRendered
	// BTypeVoid is a void progress bar will do nothing.
	BTypeVoid
)

func (BType) String

func (i BType) String() string

func (BType) Valid

func (i BType) Valid() bool

Valid checks if type is in a valid value range.

type Bar

type Bar interface {
	// Progress returns write channel, that will increase done work.
	Progress() chan<- struct{}
	// Finish stops the progress bar, means that no work left to do. Should be called in defer after bar created.
	Finish()
	// Run runs progress bar rendering. Blocking process, should be run in a goroutine.
	Run(ctx context.Context)
}

Bar is a progress bar manipulation contract.

func New

func New(max int, barType BType) Bar

New creates Bar instance for bar progress rendering. max - is the expected amount of work. barType - is a desired type of bar that constructor will return. Usage:

pBar := bar.New(len(notMutual), log.GetLevel())

go pBar.Run(ctx)

defer func() {
	pBar.Finish()
}()

for i := range 100{
	pBar.Progress() <- struct{}{}
}.

Jump to

Keyboard shortcuts

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