progressutil

package
v0.0.0-...-c61a0e3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: Apache-2.0 Imports: 8 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")
)
View Source
var (
	ErrAlreadyStarted = errors.New("cannot add copies after PrintAndWait has been called")
)

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 NewCopyProgressPrinter

func NewCopyProgressPrinter() *CopyProgressPrinter

NewCopyProgressPrinter returns a new CopyProgressPrinter

func (*CopyProgressPrinter) AddCopy

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

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. AddCopy can only be called before PrintAndWait; otherwise, ErrAlreadyStarted will be returned.

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. PrintAndWait may only be called once; any subsequent calls will immediately return ErrAlreadyStarted. After PrintAndWait has been called, no more copies may be added to the CopyProgressPrinter.

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) GetCurrentProgress

func (pb *ProgressBar) GetCurrentProgress() float64

func (*ProgressBar) GetDone

func (pb *ProgressBar) GetDone() bool

GetDone returns whether or not this progress bar is done

func (*ProgressBar) GetPrintAfter

func (pb *ProgressBar) GetPrintAfter() string

GetPrintAfter gets the text printed on the line after the progress bar.

func (*ProgressBar) GetPrintBefore

func (pb *ProgressBar) GetPrintBefore() string

GetPrintBefore gets the text printed on the line before the progress bar.

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) SetDone

func (pb *ProgressBar) SetDone(val bool)

SetDone sets whether or not this progress bar is done

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