tui

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package tui provides terminal UI styling and output formatting

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bold

func Bold(text string) string

Bold renders bold text

func Code

func Code(code string) string

Code renders styled inline code

func ConfirmPrompt added in v1.1.6

func ConfirmPrompt(message string) (bool, error)

ConfirmPrompt shows a yes/no confirmation prompt

func DetailBox

func DetailBox(title string, content string) string

DetailBox creates a styled box for detail views

func Divider

func Divider() string

Divider creates a styled horizontal divider

func ErrorMessage

func ErrorMessage(message string) string

ErrorMessage creates a styled error message

func InfoMessage

func InfoMessage(message string) string

InfoMessage creates a styled info message

func InputPrompt added in v1.1.6

func InputPrompt(prompt string) (string, error)

InputPrompt shows a text input prompt and returns the entered value

func KeyValue

func KeyValue(key, value string) string

KeyValue renders a styled key-value pair

func Muted

func Muted(text string) string

Muted renders muted/dim text

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

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

SimpleTable creates a minimal table for quick output

func StatusIcon

func StatusIcon(status string) string

StatusIcon returns an icon for a status string

func SuccessMessage

func SuccessMessage(message string) string

SuccessMessage creates a styled success message

func URL

func URL(url string) string

URL renders a styled URL

func WarningMessage

func WarningMessage(message string) string

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

type ListResult[T any] struct {
	Items []T `json:"items"`
	Total int `json:"total"`
}

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) Error

func (o *Output) Error(message string)

Error prints an error message (only in table format)

func (*Output) Format

func (o *Output) Format() OutputFormat

Format returns the current output format

func (*Output) Info

func (o *Output) Info(message string)

Info prints an info message (only in table format)

func (*Output) IsJSON

func (o *Output) IsJSON() bool

IsJSON returns true if the output format is JSON

func (*Output) Print

func (o *Output) Print(data interface{}, tableFunc func()) error

Print outputs data based on the configured format tableFunc is called for table format, data is used for JSON

func (*Output) PrintJSON

func (o *Output) PrintJSON(data interface{}) error

PrintJSON outputs data as JSON

func (*Output) PrintTable

func (o *Output) PrintTable(headers []string, rows [][]string)

PrintTable outputs data as a styled table

func (*Output) Printf

func (o *Output) Printf(format string, a ...any)

Printf prints formatted output (only in table format)

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

func (*Output) SetWriter

func (o *Output) SetWriter(w io.Writer) *Output

SetWriter sets the output writer

func (*Output) Success

func (o *Output) Success(message string)

Success prints a success message (only in table format)

func (*Output) Warning

func (o *Output) Warning(message string)

Warning prints a warning message (only in table 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

type Renderable interface {
	RenderJSON() any
	RenderTUI(out *Output)
}

Renderable is an interface for types that can render themselves in both JSON and TUI formats

type SelectOption added in v1.1.6

type SelectOption struct {
	Label string
	Value string
}

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

type StatusItem struct {
	Key    string
	Value  string
	Status string // optional: affects styling
}

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 NewStatusTable

func NewStatusTable() *StatusTable

NewStatusTable creates a new status table

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

func (*StatusTable) String

func (st *StatusTable) String() string

String renders the status table

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

func NewStyles

func NewStyles(theme *Theme) *Styles

NewStyles creates styled components from a theme

func (*Styles) StatusStyle

func (s *Styles) StatusStyle(status string) lipgloss.Style

StatusStyle returns the appropriate style for a status string

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

type WorkerSelectItem struct {
	Name     string
	WorkerID string
	Status   string
}

WorkerSelectOption creates select options from worker list with name and ID

Jump to

Keyboard shortcuts

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