wait

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package wait contains convenience functions to create a progress indicator for CLI applications, also know as a spinner. It is basically a text and a rapidly changing symbol that provides feedback to the user that something is still running even though there is no information how long it will continue to run.

Example:

package main

import (
	"time"

	"github.com/homeport/gonvenience/pkg/v1/wait"
)

func main() {
	pi := wait.NewProgressIndicator("operation in progress")

	pi.SetTimeout(10 * time.Second)
	pi.Start()

	time.Sleep(5 * time.Second)

	pi.SetText("operation *still* in progress")

	time.Sleep(5 * time.Second)

	pi.Done("Ok, done")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeInfoText

func TimeInfoText(elapsedTime time.Duration) (string, colorful.Color)

TimeInfoText is the default implementation for the time information text on the far right side of the progress indicator line.

Types

type ProgressIndicator

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

ProgressIndicator is a handle to a progress indicator (spinner).

func NewProgressIndicator

func NewProgressIndicator(format string, args ...interface{}) *ProgressIndicator

NewProgressIndicator creates a new progress indicator handle. The provided text is shown as long as the progress indicator runs, or if new text is supplied during runtime.

func (*ProgressIndicator) Done

func (pi *ProgressIndicator) Done(format string, args ...interface{}) bool

Done stops the progress indicator.

func (*ProgressIndicator) SetOutputWriter

func (pi *ProgressIndicator) SetOutputWriter(out io.Writer)

SetOutputWriter sets the output writer to used to print the progress indicator texts to, e.g. `os.Stderr` or `os.Stdout`.

func (*ProgressIndicator) SetText

func (pi *ProgressIndicator) SetText(format string, args ...interface{})

SetText updates the waiting text.

func (*ProgressIndicator) SetTimeInfoTextFunc

func (pi *ProgressIndicator) SetTimeInfoTextFunc(f func(time.Duration) (string, colorful.Color))

SetTimeInfoTextFunc sets a custom time info text function that is called to create the string and the color to be used on the far right side of the progress indicator.

func (*ProgressIndicator) SetTimeout

func (pi *ProgressIndicator) SetTimeout(timeout time.Duration)

SetTimeout specifies that the progress indicator will timeout after the provided duration. A timeout duration lower than one nanosecond means that there is no timeout.

func (*ProgressIndicator) Start

func (pi *ProgressIndicator) Start() *ProgressIndicator

Start starts the progress indicator. If it is already started, the this function returns immediately.

func (*ProgressIndicator) Stop

func (pi *ProgressIndicator) Stop() bool

Stop stops the progress indicator by clearing the line one last time

Jump to

Keyboard shortcuts

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