Documentation
¶
Overview ¶
Package tui provides interactive terminal prompts for the tingly-box CLI.
It is intentionally small and self contained: a handful of single-shot prompts (Confirm, Input, Select, MultiSelect, Spinner) plus a Wizard runner that strings them together with a shared header, breadcrumb and help line.
Index ¶
- Variables
- func RunQuickstart(mgr QuickstartManager) error
- func RunWizard[S any](title string, initial S, steps []Step[S]) (S, error)
- func WithSpinner[T any](message string, fn func() (T, error)) (T, error)
- type Action
- type ConfirmOptions
- type InputOptions
- type MultiSelectItem
- type MultiSelectOptions
- type QuickstartManager
- type Result
- func Confirm(prompt string, opts ...ConfirmOptions) (Result[bool], error)
- func Input(prompt string, opts ...InputOptions) (Result[string], error)
- func MultiSelect[T any](prompt string, items []MultiSelectItem[T], opts ...MultiSelectOptions) (Result[[]T], error)
- func Select[T any](prompt string, items []SelectItem[T], opts ...SelectOptions) (Result[T], error)
- type SelectItem
- type SelectOptions
- type Step
- type StepContext
- type StepResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrCancelled = errors.New("cancelled") ErrBack = errors.New("back") )
Common navigation outcomes.
var ErrRequired = errors.New("this field is required")
ErrRequired is returned by Input when a required field is left blank.
Functions ¶
func RunQuickstart ¶
func RunQuickstart(mgr QuickstartManager) error
RunQuickstart runs the interactive Tingly Box quickstart wizard.
Types ¶
type ConfirmOptions ¶
type ConfirmOptions struct {
Header string // optional header (rendered above the prompt)
DefaultYes bool // pressing Enter chooses Yes
CanGoBack bool // allow Esc/← to go back
Description string // optional one-line description
}
ConfirmOptions tunes a Confirm prompt.
type InputOptions ¶
type InputOptions struct {
Header string
Placeholder string
Required bool
Mask bool
Initial string
Validate func(string) error
CharLimit int
CanGoBack bool
}
InputOptions tunes an Input prompt.
type MultiSelectItem ¶
MultiSelectItem is a single row in a MultiSelect prompt.
type MultiSelectOptions ¶
MultiSelectOptions tunes a MultiSelect prompt.
type QuickstartManager ¶
type QuickstartManager interface {
ListProviders() []*typ.Provider
GetProvider(name string) (*typ.Provider, error)
AddProvider(name, apiBase, token string, apiStyle protocol.APIStyle) error
SaveConfig() error
GetServerPort() int
SetupServerWithPort(port int) error
StartServer() error
GetGlobalConfig() *serverconfig.Config
FetchAndSaveProviderModels(providerUUID string) error
}
QuickstartManager is the surface the wizard needs from the host (the CLI's AppManager). Defined here as an interface so this package stays a leaf.
type Result ¶
Result wraps a prompt value with the dismissal Action.
func Confirm ¶
func Confirm(prompt string, opts ...ConfirmOptions) (Result[bool], error)
Confirm shows a y/n prompt and returns the selection.
func Input ¶
func Input(prompt string, opts ...InputOptions) (Result[string], error)
Input shows a text-input prompt and returns the entered value.
func MultiSelect ¶
func MultiSelect[T any](prompt string, items []MultiSelectItem[T], opts ...MultiSelectOptions) (Result[[]T], error)
MultiSelect shows a many-of selection list.
func Select ¶
func Select[T any](prompt string, items []SelectItem[T], opts ...SelectOptions) (Result[T], error)
Select shows a one-of selection list.
type SelectItem ¶
SelectItem is a single row in a Select prompt.
type SelectOptions ¶
type SelectOptions struct {
Header string
Initial any // initial selection value (matched via fmt %v)
PageSize int // visible items, default 8
CanGoBack bool // allow Esc/← to go back
}
SelectOptions tunes a Select prompt.
type Step ¶
type Step[S any] struct { Name string Skip func(state S) bool Execute func(ctx StepContext, state S) (S, StepResult, error) }
Step describes a single phase in a wizard.
type StepContext ¶
type StepContext struct {
Header string // ready-to-print breadcrumb/title
Index int // 0-indexed position among the active (non-skipped) steps
Total int // total active steps
}
StepContext carries presentation info passed to each Step's Execute.
type StepResult ¶
type StepResult int
StepResult signals what the wizard should do after a step.
const ( StepContinue StepResult = iota // advance to the next step StepBack // go back to the previous step StepDone // wizard finished successfully StepSkip // skip this step StepCancel // user cancelled )