ui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package ui provides formatting and styling utilities for console output.

Index

Constants

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

Indent1 and Indent2 are one and two levels of indentation.

View Source
const (
	SymbolError = "✗"

	SymbolArrow  = "→"
	SymbolBullet = symbolInfo
)

Variables

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

	Success = lipgloss.NewStyle().Foreground(colorSuccess)
	Warning = lipgloss.NewStyle().Foreground(colorWarning)
	Error   = lipgloss.NewStyle().Foreground(colorError)

	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.

Functions

func ClearScreen

func ClearScreen()

ClearScreen clears the visible screen when stdout is a terminal.

func ComposerPhaseRules added in v0.5.0

func ComposerPhaseRules() []phaseRule

func DockerStartPhaseRules added in v0.5.0

func DockerStartPhaseRules() []phaseRule
func FileLink(text, filename string) string

FileLink links text to an absolute file path using OSC 8 in interactive terminals. Redirected output keeps the plain text.

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 InstallPhaseRules added in v0.5.0

func InstallPhaseRules() []phaseRule

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 PrintCause added in v0.5.0

func PrintCause(err error, verbose bool)

PrintCause prints the underlying error beneath a status line, but only under verbose output.

Status lines stay readable by default, while the detail needed to diagnose a failure is still one flag away rather than discarded.

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 PrintHiddenOutputTail added in v0.5.0

func PrintHiddenOutputTail(title string, lines []string)

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

func SuccessBox(message string, details []KVPair)

SuccessBox prints a success 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 PhaseTrackerWriter added in v0.5.0

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

func NewPhaseTrackerWriter added in v0.5.0

func NewPhaseTrackerWriter(spinner *Spinner, baseMessage string, rules []phaseRule) *PhaseTrackerWriter

func (*PhaseTrackerWriter) TailLines added in v0.5.0

func (w *PhaseTrackerWriter) TailLines() []string

func (*PhaseTrackerWriter) Write added in v0.5.0

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

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.

Jump to

Keyboard shortcuts

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