tui

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package tui draws codexctl's prompts and styled output. It knows nothing about profiles or Codex.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("cancelled")

Functions

func Confirm

func Confirm(env Env, opts ConfirmOptions) (bool, error)

func Input

func Input(env Env, opts InputOptions) (string, error)

func MultiSelect

func MultiSelect(env Env, opts MultiSelectOptions) ([]int, error)

func RunSteps

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

RunSteps returns ErrCancelled on Ctrl-C unless the last step finished anyway.

func Select

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

func Spin

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

Spin clears its line on success, since the caller reports the result.

Types

type Action

type Action struct {
	Key      string
	Label    string
	NeedsRow bool // only offered when a profile is focused
}

type Check

type Check struct {
	Message string
	OK      bool
}

type ConfirmOptions

type ConfirmOptions struct {
	Title       string
	Description []string
	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
}

type DashboardChoice

type DashboardChoice struct {
	Key string
	Row int
}

DashboardChoice has an empty Key when the user quit.

type DashboardOptions

type DashboardOptions struct {
	Title    string
	Subtitle string
	Notes    []Note // shown under the title
	Rows     []DashboardRow
	Results  []Note // what the last action reported
	Actions  []Action
	Cursor   int
	// Load runs in the background and its rows replace Rows.
	Load func() []DashboardRow
}

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
	Meters  []Meter
	Status  string // shown in place of meters
}

type Env

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

Env is where a program reads keys and draws; Out is normally stderr.

type Field

type Field struct {
	Label string
	Value string
}

type InputOptions

type InputOptions struct {
	Title       string
	Description []string
	Placeholder string
	Value       string
	Secret      bool
	Validate    func(string) error // checked on every key
}

type Item

type Item struct {
	Label    string
	Detail   string
	Badge    string // short tag such as "active"
	Disabled string // why the row cannot be chosen
	Checked  bool
}

type Level added in v0.3.1

type Level int
const (
	LevelInfo Level = iota
	LevelOK
	LevelWarn
	LevelFail
)

type Meter added in v0.3.2

type Meter struct {
	Label string
	Left  float64 // percent
}

type MultiSelectOptions

type MultiSelectOptions struct {
	Title string
	Items []Item
	Min   int // rows that must be checked
}

type Note

type Note struct {
	Text  string
	Level Level
}

type Reporter

type Reporter struct {
	// contains filtered or unexported fields
}

Reporter is safe to call from the step's goroutine. The zero Reporter discards everything.

func (*Reporter) Context

func (r *Reporter) Context() context.Context

Context is cancelled on Ctrl-C; the runner waits for the step either way.

func (*Reporter) Progress

func (r *Reporter) Progress(fraction float64)

Progress turns the spinner into a progress bar on its first call.

func (*Reporter) Result

func (r *Reporter) Result(text string)

type Row

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

type Screen added in v0.3.1

type Screen struct {
	// contains filtered or unexported fields
}

Screen is the alternate screen, held while the dashboard is open so it stays in place.

func OpenScreen added in v0.3.1

func OpenScreen(env Env) *Screen

func (*Screen) Close added in v0.3.1

func (s *Screen) Close()

func (*Screen) Dashboard added in v0.3.1

func (s *Screen) Dashboard(opts DashboardOptions) (DashboardChoice, error)

type SelectOptions

type SelectOptions struct {
	Title  string
	Items  []Item
	Cursor int
}

type Step

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

type Theme

type Theme struct {
	Title    lipgloss.Style
	Text     lipgloss.Style
	Muted    lipgloss.Style
	Faint    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 bound to one output stream, so a pipe or NO_COLOR gets plain text.

func NewTheme

func NewTheme(w io.Writer) *Theme

func (*Theme) Card

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

func (*Theme) Checklist

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

func (*Theme) Failure

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

func (*Theme) Hint

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

func (*Theme) Meter added in v0.3.2

func (t *Theme) Meter(left float64, width int) string

Meter is a bar of width cells, filled to the percent left and colored by how little that is.

func (*Theme) Name

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

func (*Theme) Success

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

func (*Theme) Table

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

func (*Theme) Warning

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

Jump to

Keyboard shortcuts

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