Documentation
¶
Index ¶
Constants ¶
View Source
const (
// InfiniteProgress is used with UpdateProgress to show progress without setting a percentage.
InfiniteProgress = -1.0
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmptyProgressBar ¶
type EmptyProgressBar struct{}
EmptyProgressBar is a no-op implementation of ProgressBar.
func (EmptyProgressBar) Clear ¶
func (EmptyProgressBar) Clear() error
func (EmptyProgressBar) SetTitle ¶
func (EmptyProgressBar) SetTitle(string)
func (EmptyProgressBar) UpdateProgress ¶
func (EmptyProgressBar) UpdateProgress(float64) error
type Opts ¶
type Opts = func(cfg *UIConfig)
Opts is a functional option for configuring UI operations.
func WithContext ¶
WithContext returns an Opts that sets the context.
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 UIConfig ¶
type UIConfig struct {
//nolint:containedctx // internal struct used to maintain backwards compatibility
Context context.Context
}
UIConfig holds configuration for UI operations.
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)
}
UserInterface defines the interface for user interaction.
Click to show internal directories.
Click to hide internal directories.