Documentation
¶
Overview ¶
Package tui contains terminal UI helpers.
Index ¶
- Constants
- func Confirm(message string, autoApprove bool) (bool, error)
- func Input(title, label, value string, validate InputValidator) (string, error)
- func RunDownloadProgress(title string, run func(func(deps.DownloadEvent)) error) error
- func RunStatusProgress(title string, items, required []StatusProgressItem, ...) error
- func RunTaskProgress(title string, items []TaskProgressItem, run func(TaskProgress) error) error
- func SelectList(action string, title string, items []list.Item) (string, bool, error)
- type InputValidator
- type Item
- type StatusProgressItem
- type StatusProgressStatus
- type TaskProgress
- type TaskProgressEvent
- type TaskProgressEventType
- type TaskProgressItem
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func Confirm ¶
Confirm asks the user to confirm an action, using Bubble Tea in terminals and a plain text prompt when interactive terminal UI is unavailable.
func Input ¶
func Input(title, label, value string, validate InputValidator) (string, error)
Input asks the user for one text value and validates it before returning.
func RunDownloadProgress ¶
func RunDownloadProgress(title string, run func(func(deps.DownloadEvent)) error) error
RunDownloadProgress renders deps download progress while run executes. It falls back to plain line-oriented output when stdout is not a terminal.
func RunStatusProgress ¶
func RunStatusProgress(title string, items, required []StatusProgressItem, poll func() (map[string]StatusProgressStatus, error)) error
RunStatusProgress renders status progress for a set of items. It polls once, then sleeps for one second between subsequent polls. The UI exits once every required item is Ready; non-required items may continue reconciling in the background.
func RunTaskProgress ¶
func RunTaskProgress(title string, items []TaskProgressItem, run func(TaskProgress) error) error
RunTaskProgress renders sequential task progress while run executes. The UI includes an overall expected-time bar plus per-item rows; both are expectation indicators, not exact work-completion percentages. It falls back to line-oriented output when stdout is not a terminal.
Types ¶
type InputValidator ¶
InputValidator validates text entered into an input prompt.
func Required ¶
func Required(name string) InputValidator
Required returns a validator that rejects empty input.
type Item ¶
Item is one selectable list entry.
func (Item) FilterValue ¶
FilterValue returns the searchable value for the list item.
type StatusProgressItem ¶
StatusProgressItem is one row in a status progress UI.
type StatusProgressStatus ¶
StatusProgressStatus is the current observed status for one progress item.
type TaskProgress ¶
type TaskProgress func(TaskProgressEvent)
TaskProgress emits task progress events. Its methods are nil-safe so domain code can report progress unconditionally; callers that do not need a progress UI can leave the progress value nil.
func (TaskProgress) Done ¶
func (p TaskProgress) Done(key, name, message string)
Done emits a task-done event for key with an optional completion message.
func (TaskProgress) Failed ¶
func (p TaskProgress) Failed(key, name string, err error)
Failed emits a task-failed event for key and displays err in the progress UI.
func (TaskProgress) Omitted ¶
func (p TaskProgress) Omitted(key, name string)
Omitted emits a task-omitted event for key. Omitted items are hidden and do not contribute to the overall expected-time summary.
func (TaskProgress) Skipped ¶
func (p TaskProgress) Skipped(key, name, message string)
Skipped emits a task-skipped event for key. Skipped items are rendered as satisfied and count as complete in the overall summary.
func (TaskProgress) Started ¶
func (p TaskProgress) Started(key, name, message string)
Started emits a task-started event for key. Timing metadata comes from the TaskProgressItem supplied to RunTaskProgress.
type TaskProgressEvent ¶
type TaskProgressEvent struct {
// Type is the lifecycle transition or message update being reported.
Type TaskProgressEventType
// Key identifies the item this event updates.
Key string
// Name can set or replace the item label when the event creates an item not
// present in the initial item list.
Name string
// Message is an optional user-facing detail rendered next to the item.
Message string
// Err is displayed for failed items.
Err error
}
TaskProgressEvent reports progress for one task progress item. The progress UI is intentionally event-driven so long-running operations can remain owned by their domain package while the command layer decides whether to render a TTY dashboard or line-oriented fallback.
type TaskProgressEventType ¶
type TaskProgressEventType string
TaskProgressEventType describes a lifecycle transition for one task progress row. Callers normally do not need to construct these values directly; use the TaskProgress helper methods passed to RunTaskProgress instead.
const ( // TaskProgressStarted marks an item as actively running. Started items show // elapsed time and, when Expected is set, an expectation bar until that // duration is exceeded. TaskProgressStarted TaskProgressEventType = "started" // TaskProgressDone marks an item as complete. Done items count toward the // overall completion total and contribute their full expected duration to the // overall expectation bar. TaskProgressDone TaskProgressEventType = "done" // TaskProgressOmitted removes an item from the progress UI when the caller // determines that the phase does not apply to this run. TaskProgressOmitted TaskProgressEventType = "omitted" // TaskProgressFailed marks an item as failed and displays the event error in // the progress UI. TaskProgressFailed TaskProgressEventType = "failed" // TaskProgressSkipped marks an item as already satisfied, such as a reused // local server or existing VM image. TaskProgressSkipped TaskProgressEventType = "skipped" // TaskProgressInfo updates an item's message without changing its lifecycle // state. TaskProgressInfo TaskProgressEventType = "info" )
type TaskProgressItem ¶
type TaskProgressItem struct {
// Key is the stable identifier used by events to update this row.
Key string
// Name is the user-facing row label shown in the progress UI.
Name string
// Exclude removes this item from the progress UI entirely. Excluded items do
// not render and do not contribute to the overall expected-time bar.
Exclude bool
// Success is the message shown when this item completes successfully and the
// completion event does not provide a more specific message.
Success string
// Expected is the usual duration for this task. It is used only to set user
// expectations; it is not treated as actual work completion.
Expected time.Duration
// Timeout is the maximum wait duration for this task when the caller has one.
// It is displayed as a hint after Expected is exceeded.
Timeout time.Duration
}
TaskProgressItem describes one row in a task progress UI. Items are rendered in the order provided to RunTaskProgress, and their Expected durations are summed to produce the overall expected-time bar.