tui

package
v0.17.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package tui is sdd's bubble tea layer: the transient coordinator display for long-running commands (Interactive, which lets a cliout.Coordinator own the dormant → armed → live → done lifecycle so instant work never starts a program) and the reusable init input prompts (text, select, multi-select, confirm). Both surfaces route through the one shared program runner (runner.go). It depends on the bubble-tea-free core in internal/cliout; only cmd/sdd imports this package.

Index

Constants

This section is empty.

Variables

View Source
var ErrPromptCancelled = errors.New("prompt cancelled")

ErrPromptCancelled is returned when the user aborts a prompt (ctrl+c / esc) instead of confirming a value.

Functions

func Interactive

func Interactive[T any](ctx context.Context, policy cliout.Policy, view View, work func(context.Context) (T, error)) (T, error)

Interactive runs work under a transient terminal view governed by policy, returning work's result. It is the single reusable coordinator entry for any long-running command — index, search lazy-fill, repo add, and future bulk operations. The caller has already established this is a TTY; off-TTY paths never reach here and keep plain slog on stderr.

func RunConfirm added in v0.17.0

func RunConfirm(cfg ConfirmPrompt) (bool, error)

RunConfirm runs the confirmation prompt on a TTY. Aborting (ctrl+c / esc) or empty input yields false without an error — the safe "leave it alone" side.

func RunMultiSelect added in v0.17.0

func RunMultiSelect[T any](cfg MultiSelectPrompt[T]) ([]T, error)

RunMultiSelect runs the multi-select prompt on a TTY, returning the selected options' values in option order, or ErrPromptCancelled if aborted.

func RunSelect added in v0.17.0

func RunSelect[T any](cfg SelectPrompt[T]) (T, error)

RunSelect runs the single-select prompt on a TTY, returning the chosen option's value or ErrPromptCancelled if the user aborts.

func RunTextPrompt added in v0.17.0

func RunTextPrompt(cfg TextPrompt) (string, error)

RunTextPrompt runs the text prompt on a TTY, returning the entered value (Default on empty input) or ErrPromptCancelled if the user aborts.

Types

type ConfirmPrompt added in v0.17.0

type ConfirmPrompt struct {
	Prompt string
}

ConfirmPrompt configures a single-char y/N confirmation.

type MultiSelectOption added in v0.17.0

type MultiSelectOption[T any] struct {
	Label    string
	Hint     string
	Value    T
	Selected bool
}

MultiSelectOption is one row of a multi-select prompt, carrying the domain value it stands for and its initial checked state.

type MultiSelectPrompt added in v0.17.0

type MultiSelectPrompt[T any] struct {
	Header  string
	Options []MultiSelectOption[T]
}

MultiSelectPrompt configures a cursor-navigated multi-select toggled with space; enter confirms only once at least one option is selected.

type SelectOption added in v0.17.0

type SelectOption[T any] struct {
	Label string
	Hint  string
	Value T
}

SelectOption is one row of a single- or multi-select prompt. Value is the domain value the option stands for, returned when the option is chosen.

type SelectPrompt added in v0.17.0

type SelectPrompt[T any] struct {
	Header  string
	Options []SelectOption[T]
	Cursor  int
}

SelectPrompt configures a cursor-navigated single-select. Header is printed on its own line above the options; Cursor is the initial selection.

type TextPrompt added in v0.17.0

type TextPrompt struct {
	Label   string
	Default string
	Width   int
}

TextPrompt configures a single-line text-input prompt. The rendered line is "<Label> [<Default>]: <input>"; empty input returns Default.

type View

type View struct {
	// InitialPhase is the footer label shown until the work reports its first
	// phase; from then on the label derives from the reporter's Phase snapshots.
	InitialPhase sddmodel.Phase
	// Progress carries the phase and count snapshots the footer renders. The
	// bar appears in the indexing phase once a total is present; the caller
	// advances it via absolute counts (SetTotal/Add) and phase transitions
	// (SetPhase). Nil leaves a bare spinner with the InitialPhase label.
	Progress *cliout.Reporter
	// StreamLogs, when true, emits display-eligible log entries as durable
	// lines that scroll into terminal history — the "indexing logs persist"
	// case. When false the live view is footer-only and logs stay hidden,
	// surfaced only by the teardown re-emit on a warning/error — the "search
	// indexing is transient" case.
	StreamLogs bool
}

View specs a phase-labeled footer for one operation: an initial phase label, an optional progress reporter (phase + count snapshots), and an opt-in log stream. The footer label tracks the reporter's current phase, so commands never decide a label string mid-run.

Jump to

Keyboard shortcuts

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