Documentation
¶
Overview ¶
Package ui provides formatting and styling utilities for console output.
Index ¶
- Constants
- Variables
- func ClearScreen()
- func ComposerPhaseRules() []phaseRule
- func DockerStartPhaseRules() []phaseRule
- 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 InstallPhaseRules() []phaseRule
- func NewTable(headers []string, rows [][]string) string
- func Plural(n int, singular, plural string) string
- func PrintCause(err error, verbose bool)
- func PrintDetail(message string)
- func PrintEmpty(message string)
- func PrintError(message string)
- func PrintHiddenOutputTail(title string, lines []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 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 SuccessBox(message string, details []KVPair)
- type KVPair
- type PhaseTrackerWriter
- type ProgressBar
- type Spinner
Constants ¶
const ( // Indent1 is one level of indentation. Indent1 = " " // Indent2 is two levels of indentation. Indent2 = " " )
const ( // SymbolError indicates an error. SymbolError = "✗" // SymbolArrow indicates a next step. SymbolArrow = "→" // SymbolBullet is the informational bullet symbol. SymbolBullet = symbolInfo )
Variables ¶
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 ¶ 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. Drive-letter paths gain a leading slash, and paths beginning with two slashes identify a host.
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string.
func FormatDateTime ¶
FormatDateTime renders a timestamp for key-value output.
func InstallPhaseRules ¶ added in v0.5.0
func InstallPhaseRules() []phaseRule
InstallPhaseRules returns rules for XenForo installation output.
func PrintCause ¶ added in v0.5.0
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 PrintHiddenOutputTail ¶ added in v0.5.0
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 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 SuccessBox ¶
SuccessBox prints a success message with optional key-value details.
Types ¶
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.
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 synchronized terminal spinner. The animation goroutine signals its exit on stopping; nonterminal starts print once without animation.
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). It waits for the animation goroutine to exit before returning and clearing the line.
func (*Spinner) StopWithMessage ¶
StopWithMessage stops the spinner and prints a final message.
func (*Spinner) UpdateMessage ¶
UpdateMessage updates the spinner message.