ui

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 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  = "•"
)

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

	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)
	ErrorBold   = lipgloss.NewStyle().Foreground(ColorError).Bold(true)

	Header = lipgloss.NewStyle().Bold(true).Underline(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.

Functions

func ClearScreen

func ClearScreen()

ClearScreen clears the visible screen when stdout is a terminal.

func FormatBytes

func FormatBytes(bytes int64) string

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

func FormatDate

func FormatDate(t time.Time) string

FormatDate renders a date for table cells.

func FormatDateTime

func FormatDateTime(t time.Time) string

FormatDateTime renders a timestamp for key-value output.

func InfoBox

func InfoBox(message string, details []KVPair)

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

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal reports whether f is an interactive terminal.

func NewTable

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

NewTable creates a formatted table with the default style.

func Plural

func Plural(n int, singular, plural string) string

Plural returns the count with the correct singular/plural noun.

func PrintDetail

func PrintDetail(message string)

PrintDetail prints an indented detail message (dimmed).

func PrintEmpty

func PrintEmpty(message string)

PrintEmpty prints a standard empty-result line.

func PrintError

func PrintError(message string)

PrintError prints an error message.

func PrintHint

func PrintHint(text string)

PrintHint prints an actionable next step: " → Run xf auth login to ...". Callers style embedded commands themselves.

func PrintInfo

func PrintInfo(message string)

PrintInfo prints an info message.

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 ShortHome

func ShortHome(path string) string

ShortHome abbreviates the home directory prefix of a path to ~.

func StatusIcon

func StatusIcon(status string) string

StatusIcon renders a colored status symbol.

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.

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

func (p *ProgressBar) Abandon()

Abandon ends an unfinished progress bar, clearing its line. Use this when the operation failed: Finish would paint the bar at 100%, reporting a partial or failed transfer as complete.

func (*ProgressBar) Finish

func (p *ProgressBar) Finish()

Finish completes the progress bar.

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

func (s *Spinner) Animating() bool

Animating reports whether the spinner is actively animating. It returns false when Start ran without a TTY (the message was printed once, plainly) and when the spinner is not running.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation. When stdout is not an interactive terminal, it prints the message once and returns without animating.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line. It is a no-op if Start ran without a TTY (the message was already printed once, plainly).

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