ui

package
v1.198.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(text string) error

Error writes an error message with red X to stderr (UI channel). Flow: ui.Error() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Errorf

func Errorf(format string, a ...interface{}) error

Errorf writes a formatted error message with red X to stderr (UI channel). Flow: ui.Errorf() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Info

func Info(text string) error

Info writes an info message with cyan info icon to stderr (UI channel). Flow: ui.Info() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Infof

func Infof(format string, a ...interface{}) error

Infof writes a formatted info message with cyan info icon to stderr (UI channel). Flow: ui.Infof() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func InitFormatter

func InitFormatter(ioCtx io.Context)

InitFormatter initializes the global formatter with an I/O context. This should be called once at application startup (in root.go).

func Markdown

func Markdown(content string) error

Markdown writes rendered markdown to stdout (data channel). Use this for help text, documentation, and other pipeable formatted content. Note: Delegates to globalFormatter.Markdown() for rendering, then writes to data channel.

func MarkdownMessage

func MarkdownMessage(content string) error

MarkdownMessage writes rendered markdown to stderr (UI channel). Use this for formatted UI messages and errors.

func MarkdownMessagef

func MarkdownMessagef(format string, a ...interface{}) error

MarkdownMessagef writes formatted markdown to stderr (UI channel).

func Markdownf

func Markdownf(format string, a ...interface{}) error

Markdownf writes formatted markdown to stdout (data channel).

func Success

func Success(text string) error

Success writes a success message with green checkmark to stderr (UI channel). Flow: ui.Success() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Successf

func Successf(format string, a ...interface{}) error

Successf writes a formatted success message with green checkmark to stderr (UI channel). Flow: ui.Successf() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Warning

func Warning(text string) error

Warning writes a warning message with yellow warning sign to stderr (UI channel). Flow: ui.Warning() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Warningf

func Warningf(format string, a ...interface{}) error

Warningf writes a formatted warning message with yellow warning sign to stderr (UI channel). Flow: ui.Warningf() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Write

func Write(text string) error

Write writes plain text to stderr (UI channel) without icons or automatic styling. Flow: ui.Write() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Writef

func Writef(format string, a ...interface{}) error

Writef writes formatted text to stderr (UI channel) without icons or automatic styling. Flow: ui.Writef() → terminal.Write() → io.Write(UIStream) → masking → stderr.

func Writeln

func Writeln(text string) error

Writeln writes text followed by a newline to stderr (UI channel) without icons or automatic styling. Flow: ui.Writeln() → terminal.Write() → io.Write(UIStream) → masking → stderr.

Types

type Formatter

type Formatter interface {
	// Status message formatting - standardized output with icons
	// This is the foundational method used by Success/Error/Warning/Info
	StatusMessage(icon string, style *lipgloss.Style, text string) string

	// Semantic formatting - returns styled strings with automatic icons (uses theme.StyleSet)
	// These methods use StatusMessage internally with predefined icons
	Success(text string) string                      // Returns "✓ {text}" in green
	Successf(format string, a ...interface{}) string // Returns "✓ {formatted}" in green
	Warning(text string) string                      // Returns "⚠ {text}" in yellow
	Warningf(format string, a ...interface{}) string // Returns "⚠ {formatted}" in yellow
	Error(text string) string                        // Returns "✗ {text}" in red
	Errorf(format string, a ...interface{}) string   // Returns "✗ {formatted}" in red
	Info(text string) string                         // Returns "ℹ {text}" in cyan
	Infof(format string, a ...interface{}) string    // Returns "ℹ {formatted}" in cyan
	Muted(text string) string                        // Returns muted text (gray, no icon)

	// Text formatting - returns styled strings
	Bold(text string) string    // Returns bold text
	Heading(text string) string // Returns heading-styled text
	Label(text string) string   // Returns label-styled text

	// Theme access
	Styles() *theme.StyleSet // Access to full theme-aware StyleSet

	// Capability queries (delegates to terminal.Terminal)
	ColorProfile() terminal.ColorProfile
	SupportsColor() bool

	// Markdown rendering - returns rendered markdown string (pure function, no I/O)
	// For writing markdown to channels, use package-level ui.Markdown() or ui.MarkdownMessage()
	Markdown(content string) (string, error)
}

Formatter provides text formatting with automatic degradation. Key Principle: Formatter RETURNS FORMATTED STRINGS - it never writes to streams.

Usage Pattern:

io := cmd.Context().Value(ioContextKey).(io.Context)
ui := cmd.Context().Value(uiFormatterKey).(ui.Formatter)

// Format text with automatic icons
msg := ui.Success("Deployment complete!")  // Returns "✓ Deployment complete!" in green

// Developer chooses channel
fmt.Fprintf(io.UI(), "%s\n", msg)  // UI message → stderr

Uses io.Terminal for capability detection and theme.StyleSet for styling.

var Format Formatter

Format exposes the global formatter for advanced use cases. Most code should use the package-level functions (ui.Success, ui.Error, etc.). Use this when you need the formatted string without writing it.

func NewFormatter

func NewFormatter(ioCtx io.Context, term terminal.Terminal) Formatter

NewFormatter creates a new Formatter with I/O context and terminal. Most code should use the package-level functions instead (ui.Markdown, ui.Success, etc.).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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