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 ¶
- func TimeInfoText(elapsedTime time.Duration) (string, colorful.Color)
- type ProgressIndicator
- func (pi *ProgressIndicator) Done(format string, args ...interface{}) bool
- func (pi *ProgressIndicator) SetOutputWriter(out io.Writer)
- func (pi *ProgressIndicator) SetText(format string, args ...interface{})
- func (pi *ProgressIndicator) SetTimeInfoTextFunc(f func(time.Duration) (string, colorful.Color))
- func (pi *ProgressIndicator) SetTimeout(timeout time.Duration)
- func (pi *ProgressIndicator) Start() *ProgressIndicator
- func (pi *ProgressIndicator) Stop() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TimeInfoText ¶
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