output

package
v3.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorEnabled added in v3.17.0

func ColorEnabled() bool

ColorEnabled returns false when the NO_COLOR environment variable is present See https://no-color.org for the convention

func Table added in v3.17.0

func Table(headers []string, rows [][]string, columnStyles map[string]string) string

func ValueOrDash added in v3.17.0

func ValueOrDash(s string) string

func Write

func Write(w io.Writer, v interface{}, format Format) error

Write outputs the given value in the specified format to the writer

Types

type Format

type Format string

Format represents the output format type

const (
	// FormatJSON outputs in JSON format
	FormatJSON Format = "json"
	// FormatYAML outputs in YAML format
	FormatYAML Format = "yaml"
	// FormatText outputs in plain text/default format
	FormatText    Format = "text"
	DefaultFormat Format = FormatJSON
)

type Formatter

type Formatter interface {
	// TextOutput returns the plain text representation
	TextOutput() string
}

Formatter is an interface that types must implement to support formatted output

type Viewable added in v3.17.0

type Viewable[T any] struct {
	Data   T
	Render func(T) string
}

Viewable wraps any type to provide formatted output support. It delegates JSON/YAML marshaling directly to the underlying data, while using a custom render function for text output.

func (Viewable[T]) MarshalJSON added in v3.17.0

func (v Viewable[T]) MarshalJSON() ([]byte, error)

MarshalJSON delegates JSON marshaling to the underlying data.

func (Viewable[T]) MarshalYAML added in v3.17.0

func (v Viewable[T]) MarshalYAML() (interface{}, error)

MarshalYAML delegates YAML marshaling to the underlying data.

func (Viewable[T]) TextOutput added in v3.17.0

func (v Viewable[T]) TextOutput() string

TextOutput implements the Formatter interface for text output.

Jump to

Keyboard shortcuts

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