tui

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func RunSteps(env Env, steps ...Step) error

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.

func Select

func Select(env Env, opts SelectOptions) (int, error)

Select asks the user to pick one item and returns its index.

func Spin

func Spin(env Env, title string, run func() error) error

Spin runs one step behind a spinner. The spinner line disappears when the step succeeds, since the caller reports the result, and stays marked with ✗ when it fails.

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 Check

type Check struct {
	Message string
	OK      bool
}

Check is one line of a Checklist.

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

type DashboardChoice struct {
	Key string
	Row int
}

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

type Env struct {
	In  io.Reader
	Out io.Writer
}

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 Field

type Field struct {
	Label string
	Value string
}

Field is one label and value in a Card.

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 Note

type Note struct {
	Text string
	Warn bool
}

Note is a status line under the dashboard title.

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

func (r *Reporter) Context() context.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.

func (*Reporter) Progress

func (r *Reporter) Progress(fraction float64)

Progress reports how much of the step is done, from 0 to 1. The first call turns the spinner line into a progress bar.

func (*Reporter) Result

func (r *Reporter) Result(text string)

Result replaces the step's title once it has finished, for example with what it found.

type Row

type Row struct {
	Cells  []string
	Active bool
	Faded  bool
}

Row is one line of a Table. Active rows get a dot and the accent color; Faded rows are muted.

type SelectOptions

type SelectOptions struct {
	Title  string
	Items  []Item
	Cursor int // row focused first
}

SelectOptions describes a single-choice list.

type Step

type Step struct {
	Title string
	Run   func(r *Reporter) error
}

Step is one unit of work shown with a spinner while it runs.

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.

func NewTheme

func NewTheme(w io.Writer) *Theme

NewTheme returns styles for output written to w.

func (*Theme) Card

func (t *Theme) Card(title string, badges []string, fields []Field) string

Card renders a titled box of fields, with badges beside the title.

func (*Theme) Checklist

func (t *Theme) Checklist(checks []Check) string

Checklist renders checks as ✓ and ! lines followed by a summary.

func (*Theme) Failure

func (t *Theme) Failure(message string) string

Failure renders "✗ message".

func (*Theme) Hint

func (t *Theme) Hint(message string) string

Hint renders a muted line of advice.

func (*Theme) Name

func (t *Theme) Name(name string) string

Name renders a profile or other name in the accent color.

func (*Theme) Success

func (t *Theme) Success(message string) string

Success renders "✓ message".

func (*Theme) Table

func (t *Theme) Table(header []string, rows []Row) string

Table renders rows under a header with aligned columns and no borders.

func (*Theme) Warning

func (t *Theme) Warning(message string) string

Warning renders "! message".

Jump to

Keyboard shortcuts

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