Documentation
¶
Overview ¶
Package printer provides rich terminal styling for CLI output.
This package uses herald (github.com/indaco/herald) for consistent, themed console output across the sley CLI. It provides both render functions (returning styled strings) and print functions (outputting to stdout).
Initialization ¶
Call Init with a theme name at startup to configure colors:
printer.Init("sley") // sley brand teal palette
printer.Init("dracula") // dracula dark theme
If Init is not called, the default sley theme is used.
Styling Functions ¶
Render functions return styled strings without printing:
styled := printer.Success("Operation completed")
styled := printer.Error("Something went wrong")
styled := printer.Warning("Deprecated feature")
styled := printer.Info("Processing...")
styled := printer.Bold("Important")
styled := printer.Faint("Secondary info")
Print Functions ¶
Print functions output styled text to stdout with a newline:
printer.PrintSuccess("Version bumped to 1.2.3")
printer.PrintError("Failed to read config")
printer.PrintWarning("No changelog entries found")
printer.PrintInfo("Checking dependencies...")
Badges ¶
Badge functions create bold, colored status indicators:
pass := printer.SuccessBadge("PASS")
fail := printer.ErrorBadge("FAIL")
warn := printer.WarningBadge("WARN")
Validation Formatting ¶
Specialized functions for doctor command validation output:
line := printer.FormatValidationPass("Config", "Valid YAML")
line := printer.FormatValidationFail("Version", "Invalid format")
line := printer.FormatValidationWarn("Plugin", "Deprecated option")
Color Control ¶
Disable colors for non-TTY or user preference:
printer.SetNoColor(true)
This also respects the NO_COLOR environment variable.
Index ¶
- func Bold(text string) string
- func Error(text string) string
- func ErrorBadge(text string) string
- func Faint(text string) string
- func FormatValidationFail(category, message string) string
- func FormatValidationFaint(category, message string) string
- func FormatValidationPass(category, message string) string
- func FormatValidationWarn(category, message string) string
- func Info(text string) string
- func Init(theme string)
- func NewTypography(theme string) *herald.Typography
- func PrintBold(text string)
- func PrintError(text string)
- func PrintFaint(text string)
- func PrintInfo(text string)
- func PrintSuccess(text string)
- func PrintWarning(text string)
- func ResolveTheme(name string) herald.Theme
- func SetNoColor(disabled bool)
- func SleyTheme() herald.Theme
- func Success(text string) string
- func SuccessBadge(text string) string
- func Typography() *herald.Typography
- func Warning(text string) string
- func WarningBadge(text string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatValidationFail ¶
FormatValidationFail formats a validation result with FAIL status. Uses a subtle red tag, category in normal text, message in faint.
func FormatValidationFaint ¶
FormatValidationFaint formats a validation result with all faint styling. Used for disabled or inactive items.
func FormatValidationPass ¶
FormatValidationPass formats a validation result with PASS status. Uses a subtle green tag, category in normal text, message in faint.
func FormatValidationWarn ¶
FormatValidationWarn formats a validation result with WARN status. Uses a subtle yellow tag, category in normal text, message in faint.
func Init ¶ added in v0.13.0
func Init(theme string)
Init sets the package-level Typography from the named theme. Call once at startup (e.g. in cli.go Before hook).
func NewTypography ¶ added in v0.13.0
func NewTypography(theme string) *herald.Typography
NewTypography creates a herald Typography with the named theme.
func PrintSuccess ¶
func PrintSuccess(text string)
PrintSuccess prints text with success (green) styling.
func PrintWarning ¶
func PrintWarning(text string)
PrintWarning prints text with warning (yellow) styling.
func ResolveTheme ¶ added in v0.13.0
ResolveTheme returns the herald Theme for the given name. Unknown names silently fall back to SleyTheme.
func SetNoColor ¶
func SetNoColor(disabled bool)
SetNoColor controls whether the printer uses colors. This respects the --no-color flag and NO_COLOR environment variable.
func SleyTheme ¶ added in v0.13.0
SleyTheme returns a herald Theme using the sley brand teal palette with adaptive light/dark support.
func SuccessBadge ¶
SuccessBadge returns a bold, green styled badge.
func Typography ¶ added in v0.13.0
func Typography() *herald.Typography
Typography returns the package-level herald Typography instance. Use this when you need direct access to herald elements like H1, H2, HR, etc.
func WarningBadge ¶
WarningBadge returns a bold, yellow styled badge.
Types ¶
This section is empty.