tspb

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 12 Imported by: 1

README

Terminal-Safe Progress Bar

Go Reference

Provides wrappers around github.com/schollz/progressbar/v3 that fallbacks to using log.Logger if the program does not have an attached terminal (using golang.org/x/term term.IsTerminal).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBytes

func DefaultBytes(size int64, desc string, options ...progressbar.Option) io.WriteCloser

DefaultBytes is the terminal-safe equivalent of progressbar.DefaultBytes.

func FromReader

func FromReader(r io.Reader, description string) io.ReadCloser

FromReader creates a new terminal-safe progress bar for reading from the given io.Reader.

If given an os.File, its name and size will be used to provide extra information about read progress. The description argument can include `{name}` or `{basename}` which will be replaced with the actual file's name accordingly.

If there is no terminal, an instance of RateLimitedLogger is returned.

func FromReaderWithOptions

func FromReaderWithOptions(r io.Reader, options ...progressbar.Option) io.ReadCloser

FromReaderWithOptions is a variant of FromReader that gives caller more customisation options over the progress bar.

func FromWriter

func FromWriter(w io.Writer, description string) io.WriteCloser

FromWriter creates a new terminal-safe progress bar for writing to the given io.Writer.

If given an os.File, its name and size will be used to provide extra information about read progress. The description argument can include `{name}` or `{basename}` which will be replaced with the actual file's name accordingly.

If there is no terminal, an instance of RateLimitedLogger is returned.

func FromWriterWithOptions

func FromWriterWithOptions(w io.Writer, options ...progressbar.Option) io.WriteCloser

FromWriterWithOptions is a variant of FromWriter that gives caller more customisation options over the progress bar.

Types

type RateLimitedLogger

type RateLimitedLogger struct {
	// Rate indicates how often logging is performed.
	//
	// By default, only log every 10 seconds.
	Rate *rate.Sometimes
	// Logger is the log.Logger instance that is used for logging.
	//
	// Defaults to log.Default.
	Logger *log.Logger
	// contains filtered or unexported fields
}

RateLimitedLogger is the replacement of progressbar.ProgressBar if program is not running in terminal.

func (*RateLimitedLogger) Close

func (l *RateLimitedLogger) Close() error

func (*RateLimitedLogger) Read

func (l *RateLimitedLogger) Read(p []byte) (n int, err error)

func (*RateLimitedLogger) Write

func (l *RateLimitedLogger) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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