pbar

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 10 Imported by: 0

README

SMARTY DISCLAIMER: Subject to the terms of the associated license agreement, this software is freely available for your use. This software is FREE, AS IN PUPPIES, and is a gift. Enjoy your new responsibility. This means that while we may consider enhancement requests, we may or may not choose to entertain requests at our sole and absolute discretion.

Progress Bar (PBar)

The Progress Bar (PBar) Go library provides basic text progress bar functionality.

Features
  • Configurable for progress bar length and characters used to paint the bar
  • Multi-threaded to paint independently of the underlying looping process

Import

import github.com/smartystreets/pbar

Usage

progress := pbar.NewPBar(5000) // 5000 is the target count
progress.Start()

... some looping work to do
progress.Update(counter)
... end of loop

progress.Finish()

Options

Specify any number of comma separated options as parameters to NewPBar()

For example:

progress := pbar.NewPBar(5000, pbar.BarLength(25), pbar.RefreshIntervalMilliseconds(750))
Progress Bar Label

Set the label that will be output to the left of the bar.

pbar.BarLabel("Loading index: ")
Progress Bar Length

Set the character length of the actual progress bar (not counting the summary text). Default 50.

pbar.BarLength(25)
Progress Bar Refresh Interval

Set the refresh interval of the progress bar in milliseconds. Default 500ms.

pbar.RefreshIntervalMilliseconds(750)
Progress Bar Graphic Characters

Set the graphic characters used in the progress bar.

pbar.BarLeft('⁅')
pbar.BarRight('⁆')
pbar.BarUncompleted('▭')
pbar.BarCompleted('▬')

Example Code

See cmd/main.go for a fully functional sample.

Documentation

Index

Constants

View Source
const (
	TTY = "/dev/tty" // Microsoft Windows is not supported

	BarLengthDefault       = 50
	RefreshIntervalDefault = 500 * time.Millisecond
	BarLeftDefault         = '['
	BarRightDefault        = ']'
	BarUnCompletedDefault  = ' '
	BarCompletedDefault    = '='
)

Variables

This section is empty.

Functions

func CountFileLines

func CountFileLines(path string) (count int, err error)

CountFileLines count newline characters in a file

Types

type CursorPosition

type CursorPosition struct {
	// contains filtered or unexported fields
}

type Option

type Option func(*PBar)

Option is a func type received by PBar. Each one allows configuration of the PBar.

func BarCompleted

func BarCompleted(completed rune) Option

func BarLabel

func BarLabel(label string) Option

func BarLeft

func BarLeft(left rune) Option

func BarLength

func BarLength(length int) Option

func BarRight

func BarRight(right rune) Option

func BarUncompleted

func BarUncompleted(uncompleted rune) Option

func OutputWriter

func OutputWriter(writer io.Writer) Option

func RefreshIntervalMilliseconds

func RefreshIntervalMilliseconds(interval int) Option

type PBar

type PBar struct {
	TargetCount uint64
	// contains filtered or unexported fields
}

func NewPBar

func NewPBar(targetCount uint64, options ...Option) *PBar

func (*PBar) Finish

func (this *PBar) Finish()

[locks mutex]

func (*PBar) Start

func (this *PBar) Start()

func (*PBar) Update

func (this *PBar) Update(current uint64)

[locks mutex]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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