Documentation
¶
Overview ¶
Package ui provides reusable interactive terminal UI components, standardized theming, and wrappers around the "charmbracelet/huh" and "charmbracelet/bubbles" libraries.
This package centralizes all interactive CLI components ensuring a consistent user experience and visual identity across the entire eng CLI application. It abstract away the complexity of managing terminal prompts and concurrent spinners.
Available Features ¶
- **Theming**: The `theme.EngTheme()` function supplies a consistent, adaptive light/dark mode HSL color palette across all interactive prompts.
- **Prompts**: Standardized functions for user interaction:
- `Confirm(message string, defaultVal bool)`: Yes/No prompts.
- `Input(message string, defaultVal string)`: Text input.
- `Select(message string, options []string, defaultVal string)`: Single selection.
- `MultiSelect(message string, options []string)`: Multiple selection.
- `Password(message string)`: Secret text input.
- **Spinners**: Beautiful and thread-safe progress spinners.
- `Spinner`: Single operation status and progress.
- `MultiSpinner`: For displaying multiple concurrent operations (e.g., parallel git pulls, downloading files, system updates).
Testing ¶
The prompt functions within this package are exposed as variables (e.g., `var Confirm = ConfirmImpl`) to allow them to be easily mocked during unit testing.
Index ¶
- Variables
- func ConfirmDangerImpl(message string) (bool, error)
- func ConfirmImpl(message string, defaultVal bool) (bool, error)
- func GetTerminalWidth() int
- func HelpFunc(c *cobra.Command, args []string)
- func InputImpl(message, defaultVal string) (string, error)
- func IsTerminal(w io.Writer) bool
- func MultiSelectImpl(message string, options, defaultSelected []string) ([]string, error)
- func PasswordImpl(message string) (string, error)
- func RenderContainerTable(stackName string, containerList []ContainerRow, termWidth int) string
- func RenderDiff(output string) string
- func RenderDiffLine(line string) string
- func RenderDiffStat(output string) string
- func RenderKeyValueTable(title string, rows []KeyValueRow, termWidth int) string
- func RenderStackTable(stacks []StackRow, termWidth int) string
- func RenderTable(opts TableOpts) string
- func RunContainersPager(content string) error
- func SelectImpl(message string, options []string, defaultVal string) (string, error)
- func SelectWithFilterImpl(message string, options []string, defaultVal string) (string, error)
- func Truncate(s string, maxLen int) string
- func UsageFunc(c *cobra.Command) error
- type ContainerRow
- type KeyValueRow
- type MultiProgressBar
- func (m *MultiProgressBar) AddBar(label string, totalPasses int) *ProgressBar
- func (m *MultiProgressBar) CompleteBar(bar *ProgressBar, err error)
- func (m *MultiProgressBar) Logf(format string, a ...interface{})
- func (m *MultiProgressBar) ProgressBar(i int) *ProgressBar
- func (m *MultiProgressBar) SetOverallMessage(msg string)
- func (m *MultiProgressBar) Stop()
- func (m *MultiProgressBar) Summary() (success, failed int, totalBytes int64, elapsed time.Duration)
- func (m *MultiProgressBar) UpdateBar(bar *ProgressBar, percent float64, detail string, currentPass int)
- type MultiSpinner
- type PortMapping
- type ProgressBar
- type ProgressSpinner
- type Spinnerdeprecated
- type StackRow
- type TableOpts
Constants ¶
This section is empty.
Variables ¶
var ( Confirm = ConfirmImpl ConfirmDanger = ConfirmDangerImpl Input = InputImpl Select = SelectImpl SelectWithFilter = SelectWithFilterImpl MultiSelect = MultiSelectImpl Password = PasswordImpl )
Wrapper functions for testing.
var DisableProgress = false
DisableProgress can be set to true in tests to prevent progress goroutines from spawning.
var Out io.Writer = os.Stderr
Out is the writer used for spinner output. Tests may replace it.
Functions ¶
func ConfirmDangerImpl ¶ added in v1.59.0
ConfirmDangerImpl prompts for a destructive action, defaulting to No. It uses the shared Eng huh theme so destructive confirms look identical everywhere; callers should prefer this over ad-hoc fmt.Scan confirms.
func ConfirmImpl ¶ added in v1.14.0
ConfirmImpl prompts the user with a yes/no question using the default theme.
func GetTerminalWidth ¶ added in v1.29.0
func GetTerminalWidth() int
GetTerminalWidth returns the current terminal width in columns, defaulting to 100 if unparseable.
func HelpFunc ¶ added in v1.27.0
HelpFunc returns a Cobra help function that formats help output using Lip Gloss styles.
func InputImpl ¶ added in v1.14.0
InputImpl prompts the user for text input using the default theme. defaultVal is pre-filled as the current value; empty input keeps it.
func IsTerminal ¶ added in v1.50.0
IsTerminal checks if the writer is a terminal.
func MultiSelectImpl ¶ added in v1.14.0
MultiSelectImpl prompts the user to select multiple options from a list using the default theme.
func PasswordImpl ¶ added in v1.14.0
PasswordImpl prompts the user for a secret text input using the default theme.
func RenderContainerTable ¶ added in v1.28.0
func RenderContainerTable(stackName string, containerList []ContainerRow, termWidth int) string
RenderContainerTable renders a detailed Lip Gloss table for containers in a specific stack.
func RenderDiff ¶ added in v1.64.0
RenderDiff styles full unified-diff output line by line, preserving the trailing newline behavior of the input.
func RenderDiffLine ¶ added in v1.64.0
RenderDiffLine styles a single unified-diff line for quick review. Added lines get a green background, removed lines a red background, hunk headers a muted style, and diff metadata a header style. The ---/+++ file headers are treated as metadata, not add/del. It returns the input unchanged when styling is disabled or the line is context.
func RenderDiffStat ¶ added in v1.64.0
RenderDiffStat styles diff --stat output by coloring the insertion (+) and deletion (-) markers, leaving file names and counts untouched.
func RenderKeyValueTable ¶ added in v1.57.0
func RenderKeyValueTable(title string, rows []KeyValueRow, termWidth int) string
RenderKeyValueTable renders a two-column label/value Lip Gloss table for diagnostics output such as system information.
func RenderStackTable ¶ added in v1.28.0
RenderStackTable renders a Lip Gloss table showing high-level status for Compose stacks.
func RenderTable ¶ added in v1.59.0
RenderTable renders tabula data with the shared CLI theme: bold padded header, rounded Primary border, optional per-cell StyleFunc.
func RunContainersPager ¶ added in v1.29.0
RunContainersPager launches an interactive scrollable viewport displaying rendered container status content.
func SelectImpl ¶ added in v1.14.0
SelectImpl prompts the user to select an option from a list using the default theme.
func SelectWithFilterImpl ¶ added in v1.59.0
SelectWithFilterImpl prompts with filtering enabled for long option lists. It falls back to the first option when defaultVal does not match, so Enter always works.
func Truncate ¶ added in v1.53.0
Truncate shortens s to at most maxLen runes, appending "..." when cut. It is rune-aware (never splits multibyte characters) and total-length safe: non-positive maxLen yields "", tiny limits yield a prefix without ellipsis. This is the single shared implementation; do not reimplement truncation elsewhere.
Types ¶
type ContainerRow ¶ added in v1.53.0
type ContainerRow struct {
Name string
Service string
State string
Health string
Image string
Ports []PortMapping
}
ContainerRow is a presentation DTO for one container table row.
type KeyValueRow ¶ added in v1.57.0
KeyValueRow is a presentation DTO for one labeled value row. Callers map domain types (e.g. sysinfo.SystemInfo) to rows so this package never imports domain packages.
type MultiProgressBar ¶ added in v1.50.0
type MultiProgressBar struct {
// contains filtered or unexported fields
}
MultiProgressBar manages multiple progress bars for concurrent operations.
func NewMultiProgressBar ¶ added in v1.50.0
func NewMultiProgressBar(out io.Writer) *MultiProgressBar
NewMultiProgressBar creates a new multi-progress-bar display.
func (*MultiProgressBar) AddBar ¶ added in v1.50.0
func (m *MultiProgressBar) AddBar(label string, totalPasses int) *ProgressBar
AddBar adds a new progress bar to the display.
func (*MultiProgressBar) CompleteBar ¶ added in v1.50.0
func (m *MultiProgressBar) CompleteBar(bar *ProgressBar, err error)
CompleteBar marks a bar as complete with optional error.
func (*MultiProgressBar) Logf ¶ added in v1.50.0
func (m *MultiProgressBar) Logf(format string, a ...interface{})
Logf prints a formatted message above the progress bars.
func (*MultiProgressBar) ProgressBar ¶ added in v1.50.0
func (m *MultiProgressBar) ProgressBar(i int) *ProgressBar
ProgressBar returns the progress bar at index i.
func (*MultiProgressBar) SetOverallMessage ¶ added in v1.50.0
func (m *MultiProgressBar) SetOverallMessage(msg string)
SetOverallMessage sets the overall progress message.
func (*MultiProgressBar) Stop ¶ added in v1.50.0
func (m *MultiProgressBar) Stop()
Stop completes progress output and clears active indicators.
func (*MultiProgressBar) Summary ¶ added in v1.50.0
func (m *MultiProgressBar) Summary() (success, failed int, totalBytes int64, elapsed time.Duration)
Summary returns a summary of all completed bars.
func (*MultiProgressBar) UpdateBar ¶ added in v1.50.0
func (m *MultiProgressBar) UpdateBar(bar *ProgressBar, percent float64, detail string, currentPass int)
UpdateBar updates a specific progress bar.
type MultiSpinner ¶
type MultiSpinner struct {
// contains filtered or unexported fields
}
MultiSpinner manages multiple concurrent progress indicators.
func NewMultiSpinner ¶
func NewMultiSpinner() (*MultiSpinner, error)
NewMultiSpinner creates a new multi-spinner manager.
func (*MultiSpinner) AddSpinner ¶
func (m *MultiSpinner) AddSpinner(text string) ProgressSpinner
AddSpinner adds a new spinner to the display.
type PortMapping ¶ added in v1.53.0
PortMapping is a presentation DTO for one published container port.
type ProgressBar ¶ added in v1.50.0
type ProgressBar struct {
ID int
Label string
Detail string
Percent float64
CurrentPass int
TotalPasses int
Done bool
Error error
StartTime time.Time
EndTime time.Time
// contains filtered or unexported fields
}
ProgressBar represents a single progress bar in the multi-progress display.
type ProgressSpinner ¶ added in v1.14.0
type ProgressSpinner interface {
UpdateText(text string)
Success(text ...interface{})
Fail(text ...interface{})
Warning(text ...interface{})
Info(text ...interface{})
}
ProgressSpinner defines the interface for spinner operations.
type Spinner
deprecated
type Spinner struct {
// contains filtered or unexported fields
}
Spinner manages progress bars and status updates using Lip Gloss and Bubbles.
Deprecated: prefer MultiSpinner/AddSpinner (ProgressSpinner) for new code, which shares banner semantics with theme banners and degrades cleanly when DisableProgress is set. This type is retained for existing callers.
func NewProgressSpinner ¶
NewProgressSpinner creates a spinner that displays progress as a bar.
func NewSpinner ¶
NewSpinner creates a new spinner with default theme styling.
func (*Spinner) SetProgressBar ¶
SetProgressBar sets the progress of the bar (0.0 to 1.0).
func (*Spinner) Start ¶
func (s *Spinner) Start()
Start displays initial spinner state. On terminals it also launches an animation ticker (braille frames + elapsed timer) until Stop/Success/Fail. Non-terminal output and DisableProgress keep the legacy single-print.
func (*Spinner) Stop ¶
func (s *Spinner) Stop()
Stop completes progress output and clears active indicator.
func (*Spinner) Success ¶ added in v1.51.0
Success clears the spinner and leaves a ✓ completion trace.
func (*Spinner) UpdateMessage ¶
UpdateMessage updates the message displayed next to the progress bar.
type StackRow ¶ added in v1.53.0
StackRow is a presentation DTO for one compose stack row. Callers map domain types (e.g. containers.Stack) to rows so this package never imports domain packages.
type TableOpts ¶ added in v1.59.0
type TableOpts struct {
Headers []string
Rows [][]string
// StyleFunc optionally styles a cell (row, col zero-indexed, data rows only).
StyleFunc func(row, col int) lipgloss.Style
// MaxColWidth truncates cells wider than this (runes). 0 = no truncation.
MaxColWidth int
// EmptyMsg is returned when Rows is empty.
EmptyMsg string
}
TableOpts configures RenderTable. Headers and Rows are plain strings; styling, borders, and truncation are applied centrally.