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 Pause(message string)
- func RunAgentMode(mgr TUIManager) error
- func RunProviderMode(mgr TUIManager) error
- func RunQuickstart(mgr TUIManager) error
- func RunRuleMode(mgr TUIManager) error
- func RunTUI(mgr TUIManager) 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
- type TUIManager
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 Pause ¶ added in v0.260604.1
func Pause(message string)
Pause renders a "press any key to continue" footer and blocks until a key is pressed. Use after List / Show / Refresh style operations so the printed output stays on screen instead of being pushed up by the next menu render. Errors are swallowed — Pause is best-effort UX glue, not a load-bearing prompt.
func RunAgentMode ¶ added in v0.260604.1
func RunAgentMode(mgr TUIManager) error
RunAgentMode is the entry point for the Agent mode loop. Users pick an agent type (from ListAgentInfo, so every supported scenario is listed) and then choose Apply, Show, or Restore for that agent.
func RunProviderMode ¶ added in v0.260604.1
func RunProviderMode(mgr TUIManager) error
RunProviderMode is the entry point for the Provider mode loop. It returns nil when the user backs out to the top-level menu.
func RunQuickstart ¶
func RunQuickstart(mgr TUIManager) error
RunQuickstart runs the interactive Tingly Box quickstart wizard.
func RunRuleMode ¶ added in v0.260604.1
func RunRuleMode(mgr TUIManager) error
RunRuleMode is the entry point for the Rule mode loop.
func RunTUI ¶ added in v0.260604.1
func RunTUI(mgr TUIManager) error
RunTUI renders the top-level TUI mode menu. On entry the user picks a mode — QuickStart (the guided wizard), Provider, Rule, or Agent — and is dropped into that mode. After a mode returns, the menu is shown again until the user exits.
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 = TUIManager
QuickstartManager is kept as an alias for backward compatibility.
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 )
type TUIManager ¶ added in v0.260604.1
type TUIManager interface {
// Providers
ListProviders() []*typ.Provider
GetProvider(name string) (*typ.Provider, error)
AddProvider(name, apiBase, token string, apiStyle protocol.APIStyle) (string, error)
UpdateProviderByUUID(uuid string, provider *typ.Provider) error
DeleteProviderByUUID(uuid string) error
FetchAndSaveProviderModels(providerUUID string) error
// Rules
ListRules() []typ.Rule
GetRuleByUUID(uuid string) *typ.Rule
AddRule(rule typ.Rule) error
UpdateRule(uuid string, rule typ.Rule) error
DeleteRule(uuid string) error
// Config + server
SaveConfig() error
GetGlobalConfig() *serverconfig.Config
GetServerPort() int
SetupServerWithPort(port int) error
StartServer() error
}
TUIManager is the surface the TUI needs from the host (the CLI's AppManager). Defined here as an interface so this package stays a leaf. It covers Quickstart, Provider, Rule, and Agent modes.