printer

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bold

func Bold(text string) string

Bold returns text with bold styling.

func Error

func Error(text string) string

Error returns text with error (red) styling.

func ErrorBadge

func ErrorBadge(text string) string

ErrorBadge returns a bold, red styled badge.

func Faint

func Faint(text string) string

Faint returns text with faint styling.

func FormatValidationFail

func FormatValidationFail(category, message string) string

FormatValidationFail formats a validation result with FAIL status. Uses a subtle red tag, category in normal text, message in faint.

func FormatValidationFaint

func FormatValidationFaint(category, message string) string

FormatValidationFaint formats a validation result with all faint styling. Used for disabled or inactive items.

func FormatValidationPass

func FormatValidationPass(category, message string) string

FormatValidationPass formats a validation result with PASS status. Uses a subtle green tag, category in normal text, message in faint.

func FormatValidationWarn

func FormatValidationWarn(category, message string) string

FormatValidationWarn formats a validation result with WARN status. Uses a subtle yellow tag, category in normal text, message in faint.

func Info

func Info(text string) string

Info returns text with info (cyan) styling.

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 PrintBold

func PrintBold(text string)

PrintBold prints text with bold styling.

func PrintError

func PrintError(text string)

PrintError prints text with error (red) styling.

func PrintFaint

func PrintFaint(text string)

PrintFaint prints text with faint styling.

func PrintInfo

func PrintInfo(text string)

PrintInfo prints text with info (cyan) styling.

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

func ResolveTheme(name string) herald.Theme

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

func SleyTheme() herald.Theme

SleyTheme returns a herald Theme using the sley brand teal palette with adaptive light/dark support.

func Success

func Success(text string) string

Success returns text with success (green) styling.

func SuccessBadge

func SuccessBadge(text string) string

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 Warning

func Warning(text string) string

Warning returns text with warning (yellow) styling.

func WarningBadge

func WarningBadge(text string) string

WarningBadge returns a bold, yellow styled badge.

Types

This section is empty.

Jump to

Keyboard shortcuts

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