Documentation
¶
Overview ¶
Package ui provides formatting and styling utilities for console output.
Index ¶
- Constants
- Variables
- func ClearScreen()
- func FileLink(text, filename string) string
- func FormatBytes(bytes int64) string
- func FormatDate(t time.Time) string
- func FormatDateTime(t time.Time) string
- func InfoBox(message string, details []KVPair)
- func IsTerminal(f *os.File) bool
- func NewTable(headers []string, rows [][]string) string
- func Plural(n int, singular, plural string) string
- func PrintDetail(message string)
- func PrintEmpty(message string)
- func PrintError(message string)
- func PrintHint(text string)
- func PrintInfo(message 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 ShortHome(path string) string
- func StatusIcon(status string) string
- func Step(current, total int) string
- func StepWithLabel(current, total int, label string) string
- func SuccessBox(message string, details []KVPair)
- type KVPair
- type ProgressBar
- type Spinner
- type TableStyle
Constants ¶
const ( Indent1 = " " Indent2 = " " )
Indent1 is one level of indentation (2 spaces).
const ( SymbolSuccess = "✓" SymbolWarning = "!" SymbolError = "✗" SymbolInfo = "•" SymbolSkipped = "-" SymbolPending = "○" SymbolArrow = "→" SymbolBullet = "•" )
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) 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.
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 FileLink ¶ added in v0.4.0
FileLink links text to an absolute file path using OSC 8 in interactive terminals. Redirected output keeps the plain text.
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string.
func FormatDateTime ¶
FormatDateTime renders a timestamp for key-value output.
func IsTerminal ¶
IsTerminal reports whether f is an interactive terminal.
func PrintDetail ¶
func PrintDetail(message string)
PrintDetail prints an indented detail message (dimmed).
func PrintHint ¶
func PrintHint(text string)
PrintHint prints an actionable next step: " → Run xf auth login to ...". Callers style embedded commands themselves.
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 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.
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) 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) 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) Animating ¶
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 ¶
StopWithMessage stops the spinner and prints a final message.
func (*Spinner) UpdateMessage ¶
UpdateMessage updates the spinner message.
type TableStyle ¶
TableStyle defines the visual style for tables.
func DefaultTableStyle ¶
func DefaultTableStyle() TableStyle
DefaultTableStyle returns the default table styling.