output

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package output handles formatted output for the CLI.

This package provides utilities for:

  • Structured field output (label: value format)
  • Unified diff generation with color highlighting
  • User feedback messages (Warning, Hint, Error) with TTY-aware coloring

Colors are automatically disabled when output is not a TTY, ensuring clean output when piped or redirected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(oldName, newName, oldContent, newContent string) string

Diff generates a unified diff between two strings with ANSI colors.

func DiffRaw

func DiffRaw(oldName, newName, oldContent, newContent string) string

DiffRaw generates a unified diff between two strings without colors.

func Error

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

Error prints an error message in red. Used for user-facing error messages that are not Go errors. For Go errors, use the standard error return pattern instead.

func Failed

func Failed(w io.Writer, name string, err error)

Failed prints a failure message in red. Example: "Failed /app/config: error message"

func Hint

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

Hint prints a hint message in cyan. Used to provide helpful suggestions to the user, typically following a warning. Example: "Hint: To compare with previous version, use: suve param diff /param~1"

func Indent

func Indent(s, prefix string) string

Indent adds a prefix to each line of the input string.

func Info

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

Info prints an informational message in yellow (without "Warning:" prefix). Example: "No changes staged."

func Success

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

Success prints a success message with green checkmark. Example: "✓ Set /app/config"

func Warning

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

Warning prints a warning message in yellow. Used to alert users about non-critical issues that don't prevent command execution. Example: "Warning: comparing identical versions"

Types

type Format

type Format string

Format represents the output format.

const (
	// FormatText is the default human-readable text format.
	FormatText Format = "text"
	// FormatJSON outputs structured JSON.
	FormatJSON Format = "json"
)

func ParseFormat

func ParseFormat(s string) Format

ParseFormat parses a format string and returns the Format. Returns FormatText for empty string or invalid values.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer provides formatted output methods.

func New

func New(w io.Writer) *Writer

New creates a new output writer.

func (*Writer) Field

func (o *Writer) Field(label, value string)

Field prints a labeled field.

func (*Writer) Separator

func (o *Writer) Separator()

Separator prints a separator line.

func (*Writer) Value

func (o *Writer) Value(value string)

Value prints a value with proper indentation.

Jump to

Keyboard shortcuts

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