progress

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

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

Bar - a simple, unobtrusive progress indicator Usage:

bar := New()
bar.SetTotal(3)
defer bar.Done()
bar.Increment("Step 1")
bar.Increment("Step 2")
bar.Increment("Step 3")
bar.Complete("Done")

Instantiation creates a progress bar consisiting of an optional spinner prefix followed by an indicator of the current step, the total steps, and a trailing message The behavior differs substantially if verbosity is enbled or not. When in verbose mode, it is expected that the process is otherwise printing status information to output, in which case this bar only prints a single status update to output when the current step is updated, interspersing the status line with standard program output. When verbosity is not enabled (the default), it is expected that in general output is left clean. In this case the status is continually written to standard output along with an animated spinner. The status is written one line above current, such that any errors from the rest of the process begin at the beinning of a line. Finally, the bar respects headless mode, omitting any printing unless explicitly configured to do so, and even then not doing the continual write method but the single status update in the same manner as when verbosity is enabled. Format:

[spinner] i/n t

func New

func New(verbose bool, options ...Option) *Bar

func (*Bar) Complete

func (b *Bar) Complete(text string)

Complete the spinner by advancing to the last step, printing the final text and stopping the write loop.

func (*Bar) Done

func (b *Bar) Done()

Done cancels the write loop if being used. Call in a defer statement after creation to ensure that the spinner stops

func (*Bar) Increment

func (b *Bar) Increment(text string)

Increment the currenly active step, including beginning printing on first call.

func (*Bar) SetTotal

func (b *Bar) SetTotal(n int)

SetTotal number of steps.

func (*Bar) Stopping

func (b *Bar) Stopping()

Stopping indicates the process is stopping, such as having received a context cancellation.

func (*Bar) String

func (b *Bar) String() string

type Option

type Option func(*Bar)

func WithOutput

func WithOutput(w io.Writer) Option

func WithPrintStepCounter

func WithPrintStepCounter(s bool) Option

func WithPrintWhileHeadless

func WithPrintWhileHeadless(p bool) Option

WithPrintHeadless allows for overriding the default behavior of squelching all output when the terminal is detected as headless (noninteractive)

Jump to

Keyboard shortcuts

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