progressutil

package
v0.0.0-...-08bd690 Latest Latest
Warning

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

Go to latest
Published: May 29, 2016 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorProgressOutOfBounds is returned if the progress is set to a value
	// not between 0 and 1.
	ErrorProgressOutOfBounds = fmt.Errorf("progress is out of bounds (0 to 1)")

	// ErrorNoBarsAdded is returned when no progress bars have been added to a
	// ProgressBarPrinter before PrintAndWait is called.
	ErrorNoBarsAdded = fmt.Errorf("AddProgressBar hasn't been called yet")
)

Functions

func ByteUnitStr

func ByteUnitStr(n int64) string

ByteUnitStr pretty prints a number of bytes.

Types

type CopyProgressPrinter

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

CopyProgressPrinter will perform an arbitrary number of io.Copy calls, while continually printing the progress of each copy.

func (*CopyProgressPrinter) AddCopy

func (cpp *CopyProgressPrinter) AddCopy(reader io.Reader, name string, size int64, dest io.Writer)

AddCopy adds a copy for this CopyProgressPrinter to perform. An io.Copy call will be made to copy bytes from reader to dest, and name and size will be used to label the progress bar and display how much progress has been made. If size is 0, the total size of the reader is assumed to be unknown.

func (*CopyProgressPrinter) PrintAndWait

func (cpp *CopyProgressPrinter) PrintAndWait(printTo io.Writer, printInterval time.Duration, cancel chan struct{}) error

PrintAndWait will print the progress for each copy operation added with AddCopy to printTo every printInterval. This will continue until every added copy is finished, or until cancel is written to.

type ProgressBar

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

ProgressBar represents one progress bar in a ProgressBarPrinter. Should not be created directly, use the AddProgressBar on a ProgressBarPrinter to create these.

func (*ProgressBar) SetCurrentProgress

func (pb *ProgressBar) SetCurrentProgress(progress float64) error

SetCurrentProgress sets the progress of this ProgressBar. The progress must be between 0 and 1 inclusive.

func (*ProgressBar) SetPrintAfter

func (pb *ProgressBar) SetPrintAfter(after string)

SetPrintAfter sets the text printed on the line after the progress bar.

func (*ProgressBar) SetPrintBefore

func (pb *ProgressBar) SetPrintBefore(before string)

SetPrintBefore sets the text printed on the line before the progress bar.

type ProgressBarPrinter

type ProgressBarPrinter struct {
	// DisplayWidth can be set to influence how large the progress bars are.
	// The bars will be scaled to attempt to produce lines of this number of
	// characters, but lines of different lengths may still be printed. When
	// this value is 0 (aka unset), 80 character columns are assumed.
	DisplayWidth int
	// PadToBeEven, when set to true, will make Print pad the printBefore text
	// with trailing spaces and the printAfter text with leading spaces to make
	// the progress bars the same length.
	PadToBeEven bool
	// contains filtered or unexported fields
}

ProgressBarPrinter will print out the progress of some number of ProgressBars.

func (*ProgressBarPrinter) AddProgressBar

func (pbp *ProgressBarPrinter) AddProgressBar() *ProgressBar

AddProgressBar will create a new ProgressBar, register it with this ProgressBarPrinter, and return it. This must be called at least once before PrintAndWait is called.

func (*ProgressBarPrinter) Print

func (pbp *ProgressBarPrinter) Print(printTo io.Writer) (bool, error)

Print will print out progress information for each ProgressBar that has been added to this ProgressBarPrinter. The progress will be written to printTo, and if printTo is a terminal it will draw progress bars. AddProgressBar must be called at least once before Print is called. If printing to a terminal, all draws after the first one will move the cursor up to draw over the previously printed bars.

Jump to

Keyboard shortcuts

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