Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ProgressBar ¶
type ProgressBar interface {
// UpdateProgress updates the state of the progress bar.
// The argument `progress` should be a float64 between 0 and 1,
// where 0 represents 0% completion, and 1 represents 100% completion.
// Returns an error if the update operation fails.
UpdateProgress(progress float64) error
// SetTitle sets the title of the progress bar, which is displayed next to the bar.
// The title provides context or description for the operation that is being tracked.
SetTitle(title string)
// Clear removes the progress bar from the terminal.
// Returns an error if the clearing operation fails.
Clear() error
}
ProgressBar is an interface for interacting with some visual progress-bar. It is used to show the progress of some running task (or multiple). Example (Infinite Progress without a value):
var pBar ProgressBar = ui.DefaultUi().NewProgressBar()
defer pBar.Clear()
pBar.SetTitle("Downloading...")
_ = pBar.UpdateProgress(ui.InfiniteProgress)
Example (with a value):
var pBar ProgressBar = ui.DefaultUi().NewProgressBar()
defer pBar.Clear()
pBar.SetTitle("Downloading...")
for i := 0; i <= 50; i++ {
pBar.UpdateProgress(float64(i) / 100.0)
time.Sleep(time.Millisecond * 50)
}
pBar.SetTitle("Installing...")
for i := 50; i <= 100; i++ {
pBar.UpdateProgress(float64(i) / 100.0)
time.Sleep(time.Millisecond * 50)
}
The title can be changed in the middle of the progress bar.
type ProgressType ¶
type ProgressType string
const ( InfiniteProgress = -1.0 // use UpdateProgress(InfiniteProgress) to show progress without setting a percentage SpinnerType ProgressType = "spinner" BarType ProgressType = "bar" )
type UserInterface ¶
type UserInterface interface {
Output(output string) error
OutputError(err error, opts ...Opts) error
NewProgressBar() ProgressBar
Input(prompt string) (string, error)
SelectOptions(prompt string, options []string) (int, string, error)
}
func DefaultUi ¶
func DefaultUi() UserInterface
Click to show internal directories.
Click to hide internal directories.