Categorygithub.com/coreos/ioprogress
modulepackage
0.0.0-20151023204047-4637e494fd9b
Repository: https://github.com/coreos/ioprogress.git
Documentation: pkg.go.dev

# README

ioprogress

ioprogress is a Go (golang) library with implementations of io.Reader and io.Writer that draws progress bars. The primary use case for these are for CLI applications but alternate progress bar writers can be supplied for alternate environments.

Example

Progress

Installation

Standard go get:

$ go get github.com/mitchellh/ioprogress

Usage

Here is an example of outputting a basic progress bar to the CLI as we're "downloading" from some other io.Reader (perhaps from a network connection):

// Imagine this came from some external source, such as a network connection,
// and that we have the full size of it, such as from a Content-Length HTTP
// header.
var r io.Reader

// Create the progress reader
progressR := &ioprogress.Reader{
	Reader: r,
	Size:   rSize,
}

// Copy all of the reader to some local file f. As it copies, the
// progressR will write progress to the terminal on os.Stdout. This is
// customizable.
io.Copy(f, progressR)

# Functions

ByteUnitStr pretty prints a number of bytes.
DrawTerminal returns a DrawFunc that draws a progress bar to an io.Writer that is assumed to be a terminal (and therefore respects carriage returns).
DrawTerminalf returns a DrawFunc that draws a progress bar to an io.Writer that is formatted with the given formatting function.
DrawTextFormatBar returns a DrawTextFormatFunc that draws a progress bar with the given width (in characters).
DrawTextFormatBarForW returns a DrawTextFormatFunc as described in the docs for DrawTextFormatBar, however if the io.Writer passed in is not a tty then the returned function will always return "".
DrawTextFormatBytes is a DrawTextFormatFunc that formats the progress and total into human-friendly byte formats.

# Structs

Reader is an implementation of io.Reader that draws the progress of reading some data.

# Type aliases

DrawFunc is the callback type for drawing progress.
DrawTextFormatFunc is a callback used by DrawFuncs that draw text in order to format the text into some more human friendly format.