ui

package
v0.1.7-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ui provides formatting and styling utilities for console output.

Index

Constants

View Source
const (
	Indent1 = "  "
	Indent2 = "    "
)

Indent1 is one level of indentation (2 spaces).

View Source
const (
	SymbolSuccess = "✓"
	SymbolWarning = "!"
	SymbolError   = "✗"
	SymbolInfo    = "•"
	SymbolSkipped = "-"
	SymbolPending = "○"
	SymbolArrow   = "→"
	SymbolBullet  = "•"
	SymbolCheck   = "✓"
	SymbolCross   = "✗"
)

SymbolSuccess is the success symbol.

View Source
const TablePadding = 2

TablePadding is the number of spaces to pad between columns.

Variables

View Source
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.

View Source
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.

View Source
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

SpinnerFrames are the animation frames for the spinner.

View Source
var SpinnerFramesSimple = []string{"|", "/", "-", "\\"}

SpinnerFramesSimple are simpler ASCII frames for terminals without Unicode.

Functions

func Box

func Box(title, content string) string

Box returns formatted text in a box border.

func Confirm

func Confirm(prompt string, defaultYes bool) bool

Confirm displays a confirmation prompt and returns the result. Note: This is a simple blocking prompt. For TUI, use huh forms.

func DoubleSeparator

func DoubleSeparator(width int) string

DoubleSeparator returns a double-line horizontal separator.

func ErrorBox

func ErrorBox(message string, details []KVPair)

ErrorBox prints an error message with optional key-value details.

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats a byte count as a human-readable string.

func Indent

func Indent(s string, spaces int) string

Indent indents all non-empty lines of text by the specified number of spaces.

func IndentLines

func IndentLines(lines []string, spaces int) []string

IndentLines indents each line of text by the specified number of spaces.

func InfoBox

func InfoBox(message string, details []KVPair)

InfoBox prints an info message with optional key-value details.

func KeyValue

func KeyValue(key, value string) string

KeyValue returns a formatted key-value pair.

func KeyValueBold

func KeyValueBold(key, value string) string

KeyValueBold returns a formatted key-value pair with a bold key.

func List

func List(items []string) string

List formats a slice of strings as a bulleted list.

func NewSpinnerOutputWriter

func NewSpinnerOutputWriter(spinner *Spinner, writer io.Writer) io.Writer

NewSpinnerOutputWriter creates a writer that coordinates with a spinner.

func NewTable

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

NewTable creates a formatted table with the default style.

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

func NumberedList(items []string) string

NumberedList formats a slice of strings as a numbered list.

func PrintDetail

func PrintDetail(message string)

PrintDetail prints an indented detail message (dimmed).

func PrintError

func PrintError(message string)

PrintError prints an error message.

func PrintInfo

func PrintInfo(message string)

PrintInfo prints an info message.

func PrintKeyValue

func PrintKeyValue(key, value string)

PrintKeyValue prints a key-value pair.

func PrintKeyValuePadded

func PrintKeyValuePadded(pairs []KVPair)

PrintKeyValuePadded prints key-value pairs with aligned values.

func PrintKeyValuePaddedWithIndent

func PrintKeyValuePaddedWithIndent(pairs []KVPair, indent string)

PrintKeyValuePaddedWithIndent prints key-value pairs with custom indentation.

func PrintStep

func PrintStep(current, total int, message string)

PrintStep prints a step message.

func PrintSubstep

func PrintSubstep(message string)

PrintSubstep prints an indented substep message with arrow.

func PrintSuccess

func PrintSuccess(message string)

PrintSuccess prints a success message.

func PrintTable

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

PrintTable prints a formatted table to stdout.

func PrintWarning

func PrintWarning(message string)

PrintWarning prints a warning message.

func Printf

func Printf(format string, v ...any) int

Printf is a wrapper around lipgloss.Printf for color-downsampled output.

func Println

func Println(v ...any) int

Println is a wrapper around lipgloss.Println for color-downsampled output.

func Separator

func Separator(width int) string

Separator returns a horizontal separator line.

func StatusIcon

func StatusIcon(status string) string

StatusIcon renders a colored status symbol.

func StatusTableStyle

func StatusTableStyle(_ int, _ map[string]lipgloss.Style) func(row, col int) lipgloss.Style

StatusTableStyle returns a style function for status-based table coloring.

func Step

func Step(current, total int) string

Step returns a formatted progress step indicator.

func StepWithLabel

func StepWithLabel(current, total int, label string) string

StepWithLabel returns a progress step with a label.

func SuccessBox

func SuccessBox(message string, details []KVPair)

SuccessBox prints a success message with optional key-value details. This replaces heavy double-line separators with a cleaner format.

func WarningBox

func WarningBox(message string, details []KVPair)

WarningBox prints a warning message with optional key-value details.

Types

type KVPair

type KVPair struct {
	Key   string
	Value string
}

KVPair represents a key-value pair for display.

func KV

func KV(key, value string) KVPair

KV creates a key-value pair.

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

func (p *ProgressBar) Finish()

Finish completes the 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

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given message.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line.

func (*Spinner) StopWithMessage

func (s *Spinner) StopWithMessage(status, message string)

StopWithMessage stops the spinner and prints a final message.

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(message string)

UpdateMessage updates the spinner message.

type SpinnerOutputWriter

type SpinnerOutputWriter struct {
	// contains filtered or unexported fields
}

SpinnerOutputWriter writes to a writer while managing spinner output.

func (*SpinnerOutputWriter) Write

func (w *SpinnerOutputWriter) Write(p []byte) (int, error)

type TableStyle

type TableStyle struct {
	Header    lipgloss.Style
	Cell      lipgloss.Style
	Separator string
}

TableStyle defines the visual style for tables.

func DefaultTableStyle

func DefaultTableStyle() TableStyle

DefaultTableStyle returns the default table styling.

Jump to

Keyboard shortcuts

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