ui

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package ui provides styled terminal output and interactive prompts.

Index

Constants

This section is empty.

Variables

View Source
var ErrInterrupted = errors.New("interrupted")

ErrInterrupted is returned when the spinner is cancelled via ctrl+c.

Functions

func Code

func Code(s string) string

Code returns the string styled as an inline command (bold cyan).

func ConfirmDelete

func ConfirmDelete(name, id string, repos []DeleteRepo) (bool, error)

ConfirmDelete prompts the user to confirm workspace deletion.

func ConfirmReset added in v1.0.0

func ConfirmReset(filePath string) (bool, error)

ConfirmReset prompts the user to confirm resetting a file to its default value.

func Error

func Error(msg string)

Error prints an error message with a red prefix to stderr.

func Errorf

func Errorf(format string, a ...any)

Errorf prints a formatted error message with a red prefix to stderr.

func FormatDuration added in v1.3.0

func FormatDuration(ms int64) string

FormatDuration formats a duration as a short human-readable string.

func Info

func Info(msg string)

Info prints an info message with a blue prefix.

func Print

func Print(msg string)

Print writes a line to stdout.

func Printf

func Printf(format string, a ...any)

Printf writes formatted output to stdout.

func RelativeTime

func RelativeTime(t time.Time) string

RelativeTime returns a human-friendly relative time string.

func RunStatusTable added in v1.3.0

func RunStatusTable(rows []StatusRow, display StatusDisplayConfig, resolve func(send func(StatusResolvedMsg))) ([]string, error)

RunStatusTable displays a live-updating table in TTY mode. The resolve function runs concurrently and sends StatusResolvedMsg via send as each workspace status is determined. In non-TTY mode, resolve runs to completion and a static table is printed. Returns the resolved statuses indexed by row.

func RunWithSpinner

func RunWithSpinner(title string, op SpinnerOp) error

RunWithSpinner runs op while displaying an animated spinner in TTY mode. In non-TTY mode it falls back to plain text output.

func SelectAgent added in v1.0.0

func SelectAgent(agents []AgentOption) (string, error)

SelectAgent prompts the user to choose among multiple configured agents. Returns the selected agent's exec command.

func SelectWorkspace

func SelectWorkspace(matches []WorkspaceOption) (string, error)

SelectWorkspace prompts the user to choose among multiple matching workspaces. Returns the selected workspace's ID.

func SetPlain

func SetPlain(v bool)

SetPlain forces all spinner output to use plain text mode.

func StatusStyle added in v1.3.0

func StatusStyle(status string, colorMap map[string]string) string

StatusStyle returns the status string with color applied. Colors are looked up from the provided colorMap (status name → ANSI code). Falls back to uncolored text if no color is defined for the status.

func Success

func Success(msg string)

Success prints a success message with a green prefix.

func Table

func Table(headers []string, rows [][]string) string

Table renders a styled table with the given headers and rows.

func Truncate

func Truncate(s string, maxLen int) string

Truncate shortens a string to maxLen characters, appending "..." if needed.

func Warning

func Warning(msg string)

Warning prints a warning message with a yellow prefix.

Types

type AgentOption added in v1.0.0

type AgentOption struct {
	Name string
	Exec string
}

AgentOption represents an agent choice for interactive selection.

type DeleteRepo

type DeleteRepo struct {
	Path   string
	Branch string
}

DeleteRepo holds repo display info for the delete confirmation prompt.

type SpinnerOp

type SpinnerOp func(report func(msg string)) error

SpinnerOp is the function executed while the spinner is displayed. Call report to emit progress lines shown below the spinner.

type StatusDisplayConfig added in v1.4.0

type StatusDisplayConfig struct {
	Order  map[string]int    // status name → display sort index
	Colors map[string]string // status name → ANSI color code
}

StatusDisplayConfig holds spec-derived display settings for the status table.

type StatusResolvedMsg added in v1.3.0

type StatusResolvedMsg struct {
	Index  int
	Status string
}

StatusResolvedMsg signals that a row's status has been resolved.

type StatusRow added in v1.3.0

type StatusRow struct {
	Name         string
	Repos        string
	Created      string
	CreatedAt    time.Time // used for sorting within status groups
	CachedStatus string    // last-known status for initial sort order
}

StatusRow holds the static columns for one workspace row.

type WorkspaceOption

type WorkspaceOption struct {
	ID      string
	Name    string
	Created time.Time
}

WorkspaceOption represents a workspace choice for interactive selection.

Jump to

Keyboard shortcuts

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