printer

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package printer provides table, JSON, and plain output helpers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorTitle   = color.New(color.FgCyan, color.Bold)
	ColorSuccess = color.New(color.FgGreen, color.Bold)
	ColorWarn    = color.New(color.FgYellow)
	ColorError   = color.New(color.FgRed, color.Bold)
	ColorDim     = color.New(color.Faint)
)

Functions

func Configure

func Configure(next Options)

Configure sets package-level printer defaults for optional helpers.

Types

type Format

type Format string

Format is a supported output format.

const (
	FormatTable Format = "table"
	FormatJSON  Format = "json"
	FormatPlain Format = "plain"
)

type JSONDataEnvelope

type JSONDataEnvelope struct {
	Kind string
	Data any
}

JSONDataEnvelope is an opt-in enveloped single-object JSON response.

type JSONKeyStyle

type JSONKeyStyle string

JSONKeyStyle controls how table/KV labels are converted to JSON keys.

const (
	JSONKeyStyleCamel JSONKeyStyle = ""
	JSONKeyStyleSnake JSONKeyStyle = "snake"
)

type JSONListEnvelope

type JSONListEnvelope struct {
	Kind      string
	Items     any
	Total     int
	Page      int
	PageSize  int
	Truncated bool
}

JSONListEnvelope is an opt-in enveloped list JSON response.

type Options

type Options struct {
	APIVersion            string
	JSONEnvelopeByDefault bool
	JSONKeyStyle          JSONKeyStyle
	JSONKeyOverrides      map[string]string
	TablePadding          string
	TableNoWhiteSpace     bool
	TableFooter           bool
	TableHeaderColor      bool
	DecoratedKVTable      bool
	DecoratedContent      bool
}

Options controls optional printer response metadata.

type Printer

type Printer struct {
	Out       io.Writer
	Err       io.Writer
	Format    Format
	PlainHead bool
}

Printer controls command output.

func New

func New(format Format) *Printer

New creates a Printer using stdout/stderr.

func NewWithWriters

func NewWithWriters(format Format, out, errOut io.Writer) *Printer

NewWithWriters creates a testable Printer.

func (*Printer) Content

func (p *Printer) Content(title, content string)

Content prints a titled content block.

func (*Printer) Error

func (p *Printer) Error(msg string)

Error prints an error message to stderr.

func (*Printer) Info

func (p *Printer) Info(msg string)

Info prints a plain message.

func (*Printer) JSONData

func (p *Printer) JSONData(kind string, data any) error

JSONData prints data as naked JSON. The kind parameter is kept for future extension.

func (*Printer) JSONDataEnvelope

func (p *Printer) JSONDataEnvelope(payload JSONDataEnvelope) error

JSONDataEnvelope prints an opt-in enveloped single-object JSON response.

func (*Printer) JSONList

func (p *Printer) JSONList(kind string, items any, total, page, perPage int, truncated bool) error

JSONList prints items as a naked JSON array. Pagination parameters are kept for API compatibility.

func (*Printer) JSONListEnvelope

func (p *Printer) JSONListEnvelope(payload JSONListEnvelope) error

JSONListEnvelope prints an opt-in enveloped list JSON response.

func (*Printer) KV

func (p *Printer) KV(pairs [][2]string)

KV prints key/value pairs.

func (*Printer) Success

func (p *Printer) Success(msg string)

Success prints a success message.

func (*Printer) Table

func (p *Printer) Table(headers []string, rows [][]string)

Table prints rows as table, JSON, or plain text.

func (*Printer) Warn

func (p *Printer) Warn(msg string)

Warn prints a warning message to stderr.

Jump to

Keyboard shortcuts

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