Documentation
¶
Overview ¶
Package ui provides formatting and styling utilities for console output.
Index ¶
- Constants
- Variables
- func Box(title, content string) string
- func Confirm(prompt string, defaultYes bool) bool
- func DoubleSeparator(width int) string
- func ErrorBox(message string, details []KVPair)
- func FormatBytes(bytes int64) string
- func Indent(s string, spaces int) string
- func IndentLines(lines []string, spaces int) []string
- func InfoBox(message string, details []KVPair)
- func KeyValue(key, value string) string
- func KeyValueBold(key, value string) string
- func List(items []string) string
- func NewSpinnerOutputWriter(spinner *Spinner, writer io.Writer) io.Writer
- func NewTable(headers []string, rows [][]string) string
- func NewTableWithStyles(headers []string, rows [][]string, styleFunc func(row, col int) lipgloss.Style) string
- func NumberedList(items []string) string
- func PrintDetail(message string)
- func PrintError(message string)
- func PrintInfo(message string)
- func PrintKeyValue(key, value string)
- func PrintKeyValuePadded(pairs []KVPair)
- func PrintKeyValuePaddedWithIndent(pairs []KVPair, indent string)
- func PrintStep(current, total int, message string)
- func PrintSubstep(message string)
- func PrintSuccess(message string)
- func PrintTable(headers []string, rows [][]string)
- func PrintWarning(message string)
- func Printf(format string, v ...any) int
- func Println(v ...any) int
- func Separator(width int) string
- func StatusIcon(status string) string
- func StatusTableStyle(_ int, _ map[string]lipgloss.Style) func(row, col int) lipgloss.Style
- func Step(current, total int) string
- func StepWithLabel(current, total int, label string) string
- func SuccessBox(message string, details []KVPair)
- func WarningBox(message string, details []KVPair)
- type KVPair
- type ProgressBar
- type Spinner
- type SpinnerOutputWriter
- type TableStyle
Constants ¶
const ( Indent1 = " " Indent2 = " " )
Indent1 is one level of indentation (2 spaces).
const ( SymbolSuccess = "✓" SymbolWarning = "!" SymbolError = "✗" SymbolInfo = "•" SymbolSkipped = "-" SymbolPending = "○" SymbolArrow = "→" SymbolBullet = "•" SymbolCheck = "✓" SymbolCross = "✗" )
SymbolSuccess is the success symbol.
const TablePadding = 2
TablePadding is the number of spaces to pad between columns.
Variables ¶
var ( ColorPrimary = lipgloss.Blue ColorSecondary = lipgloss.Magenta ColorAccent = lipgloss.Cyan ColorSuccess = lipgloss.Green ColorWarning = lipgloss.Yellow ColorError = lipgloss.Red ColorInfo = lipgloss.Cyan ColorSubtle = lightDark(lipgloss.Color("#585858"), lipgloss.Color("#BCBCBC")) )
ColorPrimary is the primary accent color.
var ( Bold = lipgloss.NewStyle().Bold(true) Italic = lipgloss.NewStyle().Italic(true) Underline = lipgloss.NewStyle().Underline(true) Dim = lipgloss.NewStyle().Faint(true) // Terminal's native faint/dim Muted = lipgloss.NewStyle().Foreground(ColorSubtle) // Adaptive subtle color Label = lipgloss.NewStyle().Foreground(ColorSubtle) // For labels in key-value pairs Secondary = lipgloss.NewStyle().Foreground(ColorSubtle).Bold(true) // Secondary emphasis (e.g., table headers) Success = lipgloss.NewStyle().Foreground(ColorSuccess) Warning = lipgloss.NewStyle().Foreground(ColorWarning) Error = lipgloss.NewStyle().Foreground(ColorError) Info = lipgloss.NewStyle().Foreground(ColorInfo) SuccessBold = lipgloss.NewStyle().Foreground(ColorSuccess).Bold(true) WarningBold = lipgloss.NewStyle().Foreground(ColorWarning).Bold(true) ErrorBold = lipgloss.NewStyle().Foreground(ColorError).Bold(true) InfoBold = lipgloss.NewStyle().Foreground(ColorInfo).Bold(true) Header = lipgloss.NewStyle().Bold(true).Underline(true) Subheader = lipgloss.NewStyle().Bold(true) Command = lipgloss.NewStyle().Foreground(ColorAccent) Path = lipgloss.NewStyle().Foreground(ColorSecondary) URL = lipgloss.NewStyle().Foreground(ColorPrimary).Underline(true) Version = lipgloss.NewStyle().Foreground(ColorAccent).Bold(true) )
Predefined styles for consistent use across commands.
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
SpinnerFrames are the animation frames for the spinner.
var SpinnerFramesSimple = []string{"|", "/", "-", "\\"}
SpinnerFramesSimple are simpler ASCII frames for terminals without Unicode.
Functions ¶
func Confirm ¶
Confirm displays a confirmation prompt and returns the result. Note: This is a simple blocking prompt. For TUI, use huh forms.
func DoubleSeparator ¶
DoubleSeparator returns a double-line horizontal separator.
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string.
func IndentLines ¶
IndentLines indents each line of text by the specified number of spaces.
func KeyValueBold ¶
KeyValueBold returns a formatted key-value pair with a bold key.
func NewSpinnerOutputWriter ¶
NewSpinnerOutputWriter creates a writer that coordinates with a spinner.
func NewTableWithStyles ¶
func NewTableWithStyles(headers []string, rows [][]string, styleFunc func(row, col int) lipgloss.Style) string
NewTableWithStyles creates a table with styled cells. The styleFunc receives (row, col) where row == -1 indicates the header.
func NumberedList ¶
NumberedList formats a slice of strings as a numbered list.
func PrintDetail ¶
func PrintDetail(message string)
PrintDetail prints an indented detail message (dimmed).
func PrintKeyValuePadded ¶
func PrintKeyValuePadded(pairs []KVPair)
PrintKeyValuePadded prints key-value pairs with aligned values.
func PrintKeyValuePaddedWithIndent ¶
PrintKeyValuePaddedWithIndent prints key-value pairs with custom indentation.
func PrintSubstep ¶
func PrintSubstep(message string)
PrintSubstep prints an indented substep message with arrow.
func PrintTable ¶
PrintTable prints a formatted table to stdout.
func StatusTableStyle ¶
StatusTableStyle returns a style function for status-based table coloring.
func StepWithLabel ¶
StepWithLabel returns a progress step with a label.
func SuccessBox ¶
SuccessBox prints a success message with optional key-value details. This replaces heavy double-line separators with a cleaner format.
func WarningBox ¶
WarningBox prints a warning message with optional key-value details.
Types ¶
type ProgressBar ¶
type ProgressBar struct {
// contains filtered or unexported fields
}
ProgressBar displays download or operation progress.
func NewProgressBar ¶
func NewProgressBar(total int64, message string) *ProgressBar
NewProgressBar creates a new progress bar.
func (*ProgressBar) Increment ¶
func (p *ProgressBar) Increment(amount int64)
Increment increments the progress bar by the given amount.
func (*ProgressBar) Update ¶
func (p *ProgressBar) Update(current int64)
Update updates the progress bar.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner provides a simple terminal spinner.
func NewSpinner ¶
NewSpinner creates a new spinner with the given message.
func (*Spinner) StopWithMessage ¶
StopWithMessage stops the spinner and prints a final message.
func (*Spinner) UpdateMessage ¶
UpdateMessage updates the spinner message.
type SpinnerOutputWriter ¶
type SpinnerOutputWriter struct {
// contains filtered or unexported fields
}
SpinnerOutputWriter writes to a writer while managing spinner output.
type TableStyle ¶
TableStyle defines the visual style for tables.
func DefaultTableStyle ¶
func DefaultTableStyle() TableStyle
DefaultTableStyle returns the default table styling.