ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ui provides shared formatting primitives for Veil's CLI output.

Index

Constants

This section is empty.

Variables

View Source
var (
	Success = color.New(color.FgGreen)
	Warning = color.New(color.FgYellow)
	Err     = color.New(color.FgRed, color.Bold)
	Muted   = color.New(color.FgHiBlack)
	Bold    = color.New(color.Bold)
)

Color palette — use these for inline styling beyond the helper functions.

Functions

func Debugf

func Debugf(w io.Writer, format string, args ...any)

Debugf prints a muted debug line with Printf-style formatting. The output is identical to Dimf today; the separate verb documents intent ("this is diagnostic") and leaves room for future gating behind a --verbose flag.

func Dim

func Dim(w io.Writer, msg string)

Dim prints a single muted line followed by a newline. It replaces the common `fmt.Fprintln(w, ui.Muted.Sprint(msg))` pattern seen across the runner and signals packages.

func Dimf

func Dimf(w io.Writer, format string, args ...any)

Dimf is the Printf analog of Dim.

func Errorf

func Errorf(w io.Writer, format string, args ...any)

Errorf prints a styled "error: <msg>\n" line to w with Printf-style formatting. Use this for non-cobra-return error output (e.g. internal package warnings that historically used log.Printf). For cobra RunE returns that also render an error line, use FormatError, which returns a sentinel error suitable for Cobra's error chain.

func Footer(w io.Writer, msg string)

Footer prints a dimmed footer line preceded by a blank line.

func FormatError

func FormatError(w io.Writer, msg string, hint string, cause ...error) error

FormatError prints a red "error: msg" line with an optional dimmed hint to w. Returns a sentinel error for use as a cobra RunE return value. When a cause is supplied, the returned error wraps it via %w so callers can errors.Is against the original. Only the first cause is honored; additional arguments are ignored so callers cannot accidentally over-specify.

func FormatWarning

func FormatWarning(w io.Writer, msg string, hint string)

FormatWarning prints a yellow "warning: msg" line with an optional dimmed hint to w.

func Header(w io.Writer, label string)

Header prints a bold section label followed by a newline.

func Phase

func Phase(w io.Writer, msg string)

Phase prints a muted phase header line: "msg\n"

func RedactPath

func RedactPath(s string) string

RedactPath replaces $HOME prefixes inside s with "~" so user-facing error messages don't leak the user's home-directory layout. Non-home paths pass through unchanged. An empty or unresolvable $HOME disables redaction.

func RelativeTime

func RelativeTime(t time.Time) string

RelativeTime formats a time relative to now:

<60s  → "just now"
<60m  → "Xm ago"
<24h  → "Xh ago"
<7d   → "Xd ago"
>=7d  → "2026-04-01" (date only)

func SetColor

func SetColor(mode string)

SetColor configures the global color mode. Called once from root PersistentPreRunE. mode is "auto", "always", or "never".

func Step

func Step(w io.Writer, msg string)

Step prints a success step line: " ✓ msg\n"

func TableHeader

func TableHeader(tw *tabwriter.Writer, cols ...string)

TableHeader prints dimmed, tab-separated column headers to a tabwriter.

func Warn

func Warn(w io.Writer, msg string)

Warn prints a warning step line: " ! msg\n"

func Warnf

func Warnf(w io.Writer, format string, args ...any)

Warnf prints a warning step line with Printf-style formatting: " ! <formatted message>\n"

Types

This section is empty.

Jump to

Keyboard shortcuts

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