Help us shape the future of Go! Take the 2026 Go Developer Survey

tui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package tui contains Trove's reusable Bubble Tea components: list and multi-select pickers with search/filter/pagination, text and secret inputs, a spinner, bulk-clone progress and the root dashboard.

Components render to stderr so stdout stays clean for pipes, never talk to forge providers directly (callers pass data or loader funcs in), and degrade to plain output when the session is not interactive.

Index

Constants

This section is empty.

Variables

View Source
var ErrQuit = errors.New("quit requested")

ErrQuit marks an abort where the user asked to leave Trove entirely (q or Ctrl+C), as opposed to going back one screen (esc). It is wrapped in an errs.ErrAborted error.

Functions

func CloneProgress

func CloneProgress(ctx context.Context, t *terminal.IO, title string, names []string, events <-chan services.CloneEvent)

CloneProgress consumes clone events and renders progress until events is closed. In non-interactive sessions it prints one line per finished repository to w instead of animating.

func Input

func Input(ctx context.Context, t *terminal.IO, o InputOptions) (string, error)

Input prompts for a line of text.

func Pause

func Pause(ctx context.Context, t *terminal.IO, backTo string) (bool, error)

Pause waits after a view finishes so the user can read it, then reports whether they want to go back (enter/esc) or quit (q).

func Read

func Read(ctx context.Context, t *terminal.IO, doc Document, backTo string) error

Read shows doc full screen. It returns ErrAborted when the user goes back (esc) and an error wrapping ErrQuit when they quit (q).

func Spin

func Spin(ctx context.Context, t *terminal.IO, label string, fn func(ctx context.Context) error) error

Spin runs fn while showing "⠋ label" on stderr when it is a terminal and the output mode is human. The spinner line is removed when fn returns, so results print on a clean line.

func SpinValue

func SpinValue[T any](ctx context.Context, t *terminal.IO, label string, fn func(ctx context.Context) (T, error)) (T, error)

SpinValue is Spin for functions returning a value.

Types

type Choice

type Choice struct {
	Label       string
	Description string
	Value       string
}

Choice is an option for Choose.

func Choose

func Choose(ctx context.Context, t *terminal.IO, question string, choices []Choice) (Choice, error)

Choose shows a compact single-select question ("? Provider type:").

type DashboardAction

type DashboardAction string

DashboardAction is the menu entry chosen.

const (
	ActionRepositories DashboardAction = "repositories"
	ActionPullRequests DashboardAction = "pull-requests"
	ActionIssues       DashboardAction = "issues"
	ActionPipelines    DashboardAction = "pipelines"
	ActionProviders    DashboardAction = "providers"
	ActionSettings     DashboardAction = "settings"
	ActionQuit         DashboardAction = "quit"
)

func Dashboard

Dashboard shows the root dashboard and returns the chosen action.

type DashboardData

type DashboardData struct {
	ProviderLabel string // "GitHub Personal"
	ProviderType  string // "GitHub"
	Host          string
	User          *domain.User
	Summary       *domain.AccountSummary
	Err           error
}

DashboardData is what the dashboard shows. Loader fills it asynchronously.

type DashboardOptions

type DashboardOptions struct {
	// PRTerm labels the pull request count ("Open MRs"); PRLabel names the
	// menu entry ("Merge Requests").
	PRTerm  string
	PRLabel string
	// Hidden actions are omitted (e.g. Issues for a provider without issues).
	Hidden map[DashboardAction]bool
	// RepoHint describes which repository per-repository actions use, e.g.
	// "acme/api" when run inside a checkout.
	RepoHint string
}

DashboardOptions tune the menu.

type Document

type Document struct {
	Title    string
	Subtitle string      // e.g. "#12 · open · by alice · 2d ago"
	Fields   [][2]string // label/value pairs shown under the title
	Body     string      // Markdown-ish text; rendered with light formatting
	Context  string      // right-aligned context, e.g. "◆ GitHub Personal"
}

Document is something to read in the full-screen reader, e.g. an issue.

type Facet

type Facet struct {
	Key     string // key in Item.Facets
	Label   string // "Namespace"
	Binding string // single key, e.g. "f"
}

Facet is a filterable attribute cycled with a key.

type InputOptions

type InputOptions struct {
	Label       string
	Placeholder string
	Default     string
	Help        string
	Secret      bool // mask input; the value is never rendered
	Validate    func(string) error
}

InputOptions configure a text prompt.

type Item

type Item struct {
	ID       string
	Title    string
	Subtitle string            // muted secondary text (description, host)
	Badges   []string          // short tags such as "private", "archived"
	Facets   map[string]string // filterable attributes, e.g. namespace/provider
	Value    any
}

Item is one selectable row.

type ListOptions

type ListOptions struct {
	Title       string
	Context     string // right-aligned context, e.g. "◆ GitHub Personal"
	Noun        string // plural noun for counts, e.g. "repositories"
	Multi       bool
	Items       []Item
	Facets      []Facet
	Preselected map[string]bool
	// ProtocolToggle shows the clone protocol and lets "t" switch it.
	ProtocolToggle bool
	Protocol       domain.GitProtocol
	// ConfirmLabel names the Enter action ("Clone", "Open", "Select").
	ConfirmLabel string
	// EscBack is set when the picker was opened from another screen (the
	// dashboard): esc then means "back" while q still quits Trove.
	EscBack bool
	// SearchHint is shown while typing a search, e.g. "author:name".
	SearchHint string
	// InitialID places the cursor on this item (e.g. when returning to a
	// list after reading one of its entries).
	InitialID string
}

ListOptions configure a picker.

type ListResult

type ListResult struct {
	Selected []Item
	Protocol domain.GitProtocol
}

ListResult is the picker outcome.

func RunList

func RunList(ctx context.Context, t *terminal.IO, o ListOptions) (ListResult, error)

RunList shows a single- or multi-select picker. It returns ErrAborted if the user quits.

Jump to

Keyboard shortcuts

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