ui

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 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 is one level of indentation.
	Indent1 = "  "
	// Indent2 is two levels of indentation.
	Indent2 = "    "
)
View Source
const (

	// SymbolError indicates an error.
	SymbolError = "✗"

	// SymbolArrow indicates a next step.
	SymbolArrow = "→"
	// SymbolBullet is the informational bullet symbol.
	SymbolBullet = symbolInfo
)

Variables

View Source
var (
	// Bold emphasizes text.
	Bold = lipgloss.NewStyle().Bold(true)
	// Dim uses the terminal's faint style.
	Dim = lipgloss.NewStyle().Faint(true)
	// Muted renders text in an adaptive subtle color.
	Muted = lipgloss.NewStyle().Foreground(colorSubtle)

	// Success styles successful status output.
	Success = lipgloss.NewStyle().Foreground(colorSuccess)
	// Warning styles warning status output.
	Warning = lipgloss.NewStyle().Foreground(colorWarning)
	// Error styles error status output.
	Error = lipgloss.NewStyle().Foreground(colorError)

	// ErrorBold emphasizes error output.
	ErrorBold = lipgloss.NewStyle().Foreground(colorError).Bold(true)

	// Header emphasizes and underlines headings.
	Header = lipgloss.NewStyle().Bold(true).Underline(true)

	// Command styles command text.
	Command = lipgloss.NewStyle().Foreground(colorAccent)
	// Path styles filesystem paths.
	Path = lipgloss.NewStyle().Foreground(colorSecondary)
	// URL styles URLs.
	URL = lipgloss.NewStyle().Foreground(colorPrimary).Underline(true)
	// Version styles version text.
	Version = lipgloss.NewStyle().Foreground(colorAccent).Bold(true)
)

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

ComposerPhaseRules returns rules for Composer output.

func DockerStartPhaseRules added in v0.5.0

func DockerStartPhaseRules() []phaseRule

DockerStartPhaseRules returns rules for Docker startup output.

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. Drive-letter paths gain a leading slash, and paths beginning with two slashes identify a host.

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

InstallPhaseRules returns rules for XenForo installation output.

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)

PrintHiddenOutputTail prints a titled tail of hidden output when it is nonempty.

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
}

PhaseTrackerWriter tracks complete output lines and updates a spinner for recognized phases. Its writes and tail snapshots are synchronized.

func NewPhaseTrackerWriter added in v0.5.0

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

NewPhaseTrackerWriter creates a tracker retaining the last 25 nonempty lines.

func (*PhaseTrackerWriter) TailLines added in v0.5.0

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

TailLines returns a copy of the retained complete, nonempty lines.

func (*PhaseTrackerWriter) Write added in v0.5.0

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

Write buffers output and processes lines terminated by a carriage return or newline.

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 synchronized terminal spinner. The animation goroutine signals its exit on stopping; nonterminal starts print once without animation.

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). It waits for the animation goroutine to exit before returning and clearing 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.

Jump to

Keyboard shortcuts

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