Documentation
¶
Index ¶
Constants ¶
const DefaultInterval = time.Millisecond * 250
Variables ¶
var ( SpinnerStrings = []string{"/", "-", "\\", "|"} SpinnerXStrings = []string{"+", "x"} SpinnerVStrings = []string{"v", "<", "^", ">"} ThrobberStrings = []string{".", "o", "O", "o"} BalloonStrings = []string{".", "o", "O", "@", "*", " "} PlatformStrings = []string{"_", "-"} DotsStrings = []string{". ", ".. ", "...", " "} ScrollingDotsStrings = []string{". ", ".. ", "...", " ..", " .", " "} StarDotsStrings = []string{"...", "*..", ".*.", "..*", "..."} FlipStrings = []string{"_", "_", "_", "-", "`", "'", "´", "-", "_", "_", "_"} ToggleStrings = []string{"=", "*", "-"} DQPBStrings = []string{"d", "q", "p", "b"} BoundingBarStrings = []string{ "[ ]", "[= ]", "[== ]", "[=== ]", "[ ===]", "[ ==]", "[ =]", "[ ]", "[ =]", "[ ==]", "[ ===]", "[=== ]", "[== ]", "[= ]", } Spinner = NewAnimatedString(SpinnerStrings, DefaultInterval) SpinnerX = NewAnimatedString(SpinnerXStrings, DefaultInterval) SpinnerV = NewAnimatedString(SpinnerVStrings, DefaultInterval) Throbber = NewAnimatedString(ThrobberStrings, DefaultInterval) Balloon = NewAnimatedString(BalloonStrings, DefaultInterval) Platform = NewAnimatedString(PlatformStrings, DefaultInterval) Dots = NewAnimatedString(DotsStrings, DefaultInterval) ScrollingDots = NewAnimatedString(ScrollingDotsStrings, DefaultInterval) StarDots = NewAnimatedString(StarDotsStrings, DefaultInterval) Flip = NewAnimatedString(FlipStrings, DefaultInterval) Toggle = NewAnimatedString(ToggleStrings, DefaultInterval) DQPB = NewAnimatedString(DQPBStrings, DefaultInterval) BoundingBar = NewAnimatedString(BoundingBarStrings, DefaultInterval) )
Functions ¶
func PrintProgress ¶
func PrintProgress(f func(*Printer) error, configs ...ConfigFunc) error
PrintProgress creates a printer with the given configs and calls the function with a reference to the printer. The printer is configured to refresh during the function call then stop once it returns.
Types ¶
type AnimatedString ¶
type AnimatedString struct {
// contains filtered or unexported fields
}
AnimatedString is an implementation of the Stringer interface that returns the next part of the string in a cycle based on the time since the string was created. Used to create spinners and throbbers in the terminal.
func NewAnimatedString ¶
func NewAnimatedString(parts []string, interval time.Duration) *AnimatedString
NewAnimatedString makes an animated string with the given string list (which animates left to right) and animation interval.
func NewStaticString ¶
func NewStaticString(value string) *AnimatedString
NewStaticString creates an animated string that only has a single frame.
func (*AnimatedString) String ¶
func (ac *AnimatedString) String() string
String returns the current string in the animation cycle.
type ConfigFunc ¶
type ConfigFunc func(*printerConfig)
ConfigFunc is a function used to initialize a printer.
func WithInterval ¶
func WithInterval(interval time.Duration) ConfigFunc
WithInterval sets the default refresh interval for a Printer.
func WithWriter ¶
func WithWriter(writer io.Writer) ConfigFunc
WithWriter sets the writer backing a Printer.
type Content ¶
type Content struct {
// contains filtered or unexported fields
}
Content is a wrapper around formatted strings which can be applied to a Printer atomically.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer adds functionality over an io.Writer which uses ANSI codes to delete and overwrite previously written content.
func NewPrinter ¶
func NewPrinter(configs ...ConfigFunc) *Printer
NewPrinter creates a new Printer with the given configs.
func NewStderrPrinter ¶
func NewStderrPrinter() *Printer
NewStderrPrinter creates a printer that writes to stderr.
func NewStdoutPrinter ¶
func NewStdoutPrinter() *Printer
NewStdoutPrinter creates a printer that writes to stdout.
func (*Printer) Refresh ¶
Refresh starts a goroutine that re-writes the last chunk of content to the screen. This will have the effect of animating strings in the content.
func (*Printer) WriteContent ¶
WriteContent clears the content written by the last call to WriteContent, then writes the new content to the backing writer.
func (*Printer) WriteString ¶
WriteString calls WriteContent described by given format string and arg list.

