Documentation
¶
Overview ¶
Package tui provides terminal UI styling and output formatting
Index ¶
- func Bold(text string) string
- func Code(code string) string
- func ConfirmPrompt(message string) (bool, error)
- func DetailBox(title string, content string) string
- func Divider() string
- func ErrorMessage(message string) string
- func InfoMessage(message string) string
- func InputPrompt(prompt string) (string, error)
- func KeyValue(key, value string) string
- func Muted(text string) string
- func SelectPrompt(title string, options []SelectOption) (string, error)
- func SimpleTable(headers []string, rows [][]string) string
- func StatusIcon(status string) string
- func SuccessMessage(message string) string
- func URL(url string) string
- func WarningMessage(message string) string
- type ActionResult
- type DetailResult
- type ListResult
- type Output
- func (o *Output) Error(message string)
- func (o *Output) Format() OutputFormat
- func (o *Output) Info(message string)
- func (o *Output) IsJSON() bool
- func (o *Output) Print(data interface{}, tableFunc func()) error
- func (o *Output) PrintJSON(data interface{}) error
- func (o *Output) PrintTable(headers []string, rows [][]string)
- func (o *Output) Printf(format string, a ...any)
- func (o *Output) Println(a ...interface{})
- func (o *Output) Render(r Renderable) error
- func (o *Output) SetFormat(format OutputFormat) *Output
- func (o *Output) SetWriter(w io.Writer) *Output
- func (o *Output) Success(message string)
- func (o *Output) Warning(message string)
- type OutputConfig
- type OutputFormat
- type Renderable
- type SelectOption
- type StatusItem
- type StatusTable
- type Styles
- type TableBuilder
- type Theme
- type WorkerSelectItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfirmPrompt ¶ added in v1.1.6
ConfirmPrompt shows a yes/no confirmation prompt
func ErrorMessage ¶
ErrorMessage creates a styled error message
func InfoMessage ¶
InfoMessage creates a styled info message
func InputPrompt ¶ added in v1.1.6
InputPrompt shows a text input prompt and returns the entered value
func SelectPrompt ¶ added in v1.1.6
func SelectPrompt(title string, options []SelectOption) (string, error)
SelectPrompt shows an interactive selection prompt and returns the selected value Returns the selected option's value and any error
func SimpleTable ¶
SimpleTable creates a minimal table for quick output
func StatusIcon ¶
StatusIcon returns an icon for a status string
func SuccessMessage ¶
SuccessMessage creates a styled success message
func WarningMessage ¶
WarningMessage creates a styled warning message
Types ¶
type ActionResult ¶
type ActionResult struct {
Success bool `json:"success"`
Message string `json:"message"`
ID string `json:"id,omitempty"`
}
ActionResult represents the result of an action (create, update, delete)
func NewActionResult ¶
func NewActionResult(success bool, message string, id string) ActionResult
NewActionResult creates a new action result
type DetailResult ¶
type DetailResult[T any] struct { Item T `json:"item"` }
DetailResult wraps a single item for JSON output
func NewDetailResult ¶
func NewDetailResult[T any](item T) DetailResult[T]
NewDetailResult creates a new detail result
type ListResult ¶
ListResult is a generic result type for list commands
func NewListResult ¶
func NewListResult[T any](items []T) ListResult[T]
NewListResult creates a new list result
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output handles rendering data in different formats
func NewOutput ¶
func NewOutput() *Output
NewOutput creates a new output handler with default config
func NewOutputWithFormat ¶
func NewOutputWithFormat(format OutputFormat) *Output
NewOutputWithFormat creates a new output handler with specified format
func (*Output) Format ¶
func (o *Output) Format() OutputFormat
Format returns the current output format
func (*Output) Print ¶
Print outputs data based on the configured format tableFunc is called for table format, data is used for JSON
func (*Output) PrintTable ¶
PrintTable outputs data as a styled table
func (*Output) Println ¶
func (o *Output) Println(a ...interface{})
Println prints a line (only in table format)
func (*Output) Render ¶
func (o *Output) Render(r Renderable) error
Render outputs the renderable data based on the configured format
func (*Output) SetFormat ¶
func (o *Output) SetFormat(format OutputFormat) *Output
SetFormat sets the output format
type OutputConfig ¶
type OutputConfig struct {
Format OutputFormat
Writer io.Writer
Styles *Styles
}
OutputConfig holds output configuration
func DefaultOutputConfig ¶
func DefaultOutputConfig() *OutputConfig
DefaultOutputConfig returns default output configuration
type OutputFormat ¶
type OutputFormat string
OutputFormat represents the output format type
const ( FormatTable OutputFormat = "table" FormatJSON OutputFormat = "json" FormatWide OutputFormat = "wide" )
func ParseOutputFormat ¶
func ParseOutputFormat(s string) OutputFormat
ParseOutputFormat parses a string into an OutputFormat
type Renderable ¶
Renderable is an interface for types that can render themselves in both JSON and TUI formats
type SelectOption ¶ added in v1.1.6
SelectOption represents an option in a selection prompt
func FormatIPOptions ¶ added in v1.1.6
func FormatIPOptions(ips []string) []SelectOption
FormatIPOptions formats IP addresses into select options
func FormatWorkerOptions ¶ added in v1.1.6
func FormatWorkerOptions(workers []WorkerSelectItem) []SelectOption
FormatWorkerOptions formats workers into select options
type StatusItem ¶
StatusItem represents a key-value status item
type StatusTable ¶
type StatusTable struct {
// contains filtered or unexported fields
}
StatusTable creates a table optimized for status displays
func (*StatusTable) Add ¶
func (st *StatusTable) Add(key, value string) *StatusTable
Add adds a status item
func (*StatusTable) AddWithStatus ¶
func (st *StatusTable) AddWithStatus(key, value, status string) *StatusTable
AddWithStatus adds a status item with status styling
type Styles ¶
type Styles struct {
Theme *Theme
// Title styles
Title lipgloss.Style
Subtitle lipgloss.Style
// Text styles
Text lipgloss.Style
Muted lipgloss.Style
Bold lipgloss.Style
// Status styles
Success lipgloss.Style
Warning lipgloss.Style
Error lipgloss.Style
Info lipgloss.Style
// Component styles
Key lipgloss.Style
Value lipgloss.Style
URL lipgloss.Style
Code lipgloss.Style
// Box styles
Box lipgloss.Style
SuccessBox lipgloss.Style
ErrorBox lipgloss.Style
InfoBox lipgloss.Style
// Table styles
TableHeader lipgloss.Style
TableCell lipgloss.Style
TableBorder lipgloss.Style
}
Styles contains all the pre-built lipgloss styles
func DefaultStyles ¶
func DefaultStyles() *Styles
DefaultStyles returns styled components using the default theme
type TableBuilder ¶
type TableBuilder struct {
// contains filtered or unexported fields
}
TableBuilder provides a fluent API for building styled tables
func NewTable ¶
func NewTable() *TableBuilder
NewTable creates a new table builder with default styles
func NewTableWithStyles ¶
func NewTableWithStyles(styles *Styles) *TableBuilder
NewTableWithStyles creates a new table builder with custom styles
func (*TableBuilder) Headers ¶
func (tb *TableBuilder) Headers(headers ...string) *TableBuilder
Headers sets the table headers
func (*TableBuilder) Row ¶
func (tb *TableBuilder) Row(cells ...string) *TableBuilder
Row adds a row to the table
func (*TableBuilder) Rows ¶
func (tb *TableBuilder) Rows(rows [][]string) *TableBuilder
Rows adds multiple rows to the table
func (*TableBuilder) String ¶
func (tb *TableBuilder) String() string
String renders the table as a string
func (*TableBuilder) Widths ¶
func (tb *TableBuilder) Widths(widths ...int) *TableBuilder
Widths sets column widths (optional)
type Theme ¶
type Theme struct {
// Primary colors
Primary lipgloss.Color
Secondary lipgloss.Color
Accent lipgloss.Color
// Text colors
Text lipgloss.Color
TextMuted lipgloss.Color
TextDim lipgloss.Color
// Status colors
Success lipgloss.Color
Warning lipgloss.Color
Error lipgloss.Color
Info lipgloss.Color
// Table colors
TableBorder lipgloss.Color
TableHeader lipgloss.Color
TableRowOdd lipgloss.Color
TableRowEven lipgloss.Color
}
Theme defines the color palette for the TUI
func DefaultTheme ¶
func DefaultTheme() *Theme
DefaultTheme returns the default GPU Go theme Inspired by cyberpunk/neon aesthetics with a GPU/compute feel
type WorkerSelectItem ¶ added in v1.1.6
WorkerSelectOption creates select options from worker list with name and ID