Documentation
¶
Overview ¶
Package tui draws codexctl's interactive prompts and styled output with Bubble Tea and Lip Gloss. It knows nothing about profiles or Codex; the cli package decides when a terminal is interactive and adapts its data.
Index ¶
- Variables
- func Confirm(env Env, opts ConfirmOptions) (bool, error)
- func Input(env Env, opts InputOptions) (string, error)
- func MultiSelect(env Env, opts MultiSelectOptions) ([]int, error)
- func RunSteps(env Env, steps ...Step) error
- func Select(env Env, opts SelectOptions) (int, error)
- func Spin(env Env, title string, run func() error) error
- type Action
- type Check
- type ConfirmOptions
- type DashboardChoice
- type DashboardOptions
- type DashboardRow
- type Env
- type Field
- type InputOptions
- type Item
- type MultiSelectOptions
- type Note
- type Reporter
- type Row
- type SelectOptions
- type Step
- type Theme
- func (t *Theme) Card(title string, badges []string, fields []Field) string
- func (t *Theme) Checklist(checks []Check) string
- func (t *Theme) Failure(message string) string
- func (t *Theme) Hint(message string) string
- func (t *Theme) Name(name string) string
- func (t *Theme) Success(message string) string
- func (t *Theme) Table(header []string, rows []Row) string
- func (t *Theme) Warning(message string) string
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("cancelled")
ErrCancelled is returned when the user leaves a prompt with Esc or Ctrl-C.
Functions ¶
func Confirm ¶
func Confirm(env Env, opts ConfirmOptions) (bool, error)
Confirm asks a yes/no question. Esc and Ctrl-C return ErrCancelled.
func Input ¶
func Input(env Env, opts InputOptions) (string, error)
Input asks for one line of text and returns it without surrounding space.
func MultiSelect ¶
func MultiSelect(env Env, opts MultiSelectOptions) ([]int, error)
MultiSelect asks the user to check items and returns their indexes.
func RunSteps ¶
RunSteps runs each step in order behind a spinner and stops at the first failure, returning its error. Ctrl-C cancels the running step's context and waits for it to return. If it failed or steps remain, RunSteps returns ErrCancelled; a last step that finished anyway counts as success.
Types ¶
type Action ¶
type Action struct {
Key string
Label string
NeedsRow bool // only offered when a profile is focused
}
Action is a key the dashboard answers to.
type ConfirmOptions ¶
type ConfirmOptions struct {
Title string
Description []string // lines shown under the title
Affirmative string // label of the yes button; "Yes" when empty
Negative string // label of the no button; "No" when empty
Default bool // which button is focused first
Danger bool // draw the yes button in red
}
ConfirmOptions describes a yes/no question.
type DashboardChoice ¶
DashboardChoice is what the user asked for. Key is empty when they quit.
func Dashboard ¶
func Dashboard(env Env, opts DashboardOptions) (DashboardChoice, error)
Dashboard shows profiles and waits for an action key.
type DashboardOptions ¶
type DashboardOptions struct {
Title string
Subtitle string // muted text beside the title, such as a version
Notes []Note
Rows []DashboardRow
Actions []Action
Cursor int
}
DashboardOptions describes the dashboard.
type DashboardRow ¶
type DashboardRow struct {
Name string
Detail string // account summary shown beside the name
Extra string // more detail shown under the list for the focused row
Active bool
Invalid bool
}
DashboardRow is one profile on the dashboard.
type Env ¶
Env is where an interactive program reads keys and draws. Out is normally stderr, so a command's stdout stays clean for its result.
type InputOptions ¶
type InputOptions struct {
Title string
Description []string
Placeholder string
Value string
Secret bool // mask what is typed, for API keys
Validate func(string) error // checked on every key; enter needs nil
}
InputOptions describes a one-line text question.
type Item ¶
type Item struct {
Label string // primary text, such as a profile name
Detail string // muted text after the label
Badge string // short tag such as "active"
Disabled string // when set, the row cannot be chosen and this says why
Checked bool // initial state in a multi-select
}
Item is one row of a selection list.
type MultiSelectOptions ¶
type MultiSelectOptions struct {
Title string
Items []Item
Min int // how many rows must be checked to continue
}
MultiSelectOptions describes a checkbox list.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter lets a running step update its line. It is safe to call from the step's goroutine. The zero Reporter discards everything, for running a step without a terminal.
func (*Reporter) Context ¶
Context is cancelled when the user presses Ctrl-C. Steps that can stop early should watch it; the runner waits for the step either way.
type Row ¶
Row is one line of a Table. Active rows get a dot and the accent color; Faded rows are muted.
type SelectOptions ¶
SelectOptions describes a single-choice list.
type Theme ¶
type Theme struct {
Title lipgloss.Style
Text lipgloss.Style
Muted lipgloss.Style
Accent lipgloss.Style
OK lipgloss.Style
Warn lipgloss.Style
Err lipgloss.Style
Key lipgloss.Style
Cursor lipgloss.Style
Selected lipgloss.Style
Header lipgloss.Style
Box lipgloss.Style
Badge lipgloss.Style
Button lipgloss.Style
ButtonOn lipgloss.Style
Danger lipgloss.Style
// contains filtered or unexported fields
}
Theme is a set of styles bound to one output stream. Colors are chosen for that stream, so a pipe, a dumb terminal or NO_COLOR gets plain text.