Help us shape the future of Go! Take the 2026 Go Developer Survey

uitypes

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorTipKey = keyTypeString("errorTip")

ErrorTipKey is the name to be used for an error tip context key. It should be used if setting an additional helpful tip into a context.Context that is then rendered as part of an error's presentation.

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

func WithContext(ctx context.Context) Opts

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.

Jump to

Keyboard shortcuts

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