output

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package output provides output formatting for CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsColorEnabled

func IsColorEnabled(noColor bool) bool

IsColorEnabled returns whether color should be enabled given the flag.

func RenderTable

func RenderTable(w io.Writer, headers []string, rows [][]string, colors *Colors) error

RenderTable writes a formatted table to w. If colors are not enabled, falls back to SimpleTable. If colors enabled, uses lipgloss/table with styled headers and alternating rows.

func SimpleTable

func SimpleTable(w io.Writer, headers []string, rows [][]string) error

SimpleTable writes a plain table using text/tabwriter (no-color fallback).

func WriteJSON

func WriteJSON(w io.Writer, v any) error

WriteJSON writes v as indented JSON to w.

func WriteTSV

func WriteTSV(w io.Writer, headers []string, rows [][]string) error

WriteTSV writes rows as tab-separated values. Headers are written as the first row if non-empty.

Types

type Colors

type Colors struct {
	Profile termenv.Profile
	// contains filtered or unexported fields
}

Colors provides terminal color support with profile detection.

func NewColors

func NewColors(noColor bool) *Colors

NewColors creates a Colors instance. If noColor is true or NO_COLOR env is set, colors are disabled.

func (*Colors) Bold

func (c *Colors) Bold(s string) string

Bold returns the string in bold.

func (*Colors) Dim

func (c *Colors) Dim(s string) string

Dim returns the string in faint style.

func (*Colors) Enabled

func (c *Colors) Enabled() bool

Enabled returns whether colors are enabled.

func (*Colors) Error

func (c *Colors) Error(s string) string

Error returns the string styled as red.

func (*Colors) Style

func (c *Colors) Style() lipgloss.Style

Style returns a lipgloss.Style. Returns empty style if colors disabled.

func (*Colors) Success

func (c *Colors) Success(s string) string

Success returns the string styled as green.

func (*Colors) Warning

func (c *Colors) Warning(s string) string

Warning returns the string styled as yellow.

type Formatter

type Formatter struct {
	Writer io.Writer
	Mode   Mode
	Colors *Colors
}

Formatter provides a unified interface for outputting data.

func NewFormatter

func NewFormatter(w io.Writer, jsonFlag, plainFlag, noColor bool) *Formatter

NewFormatter creates a formatter with the given settings.

func (*Formatter) Output

func (f *Formatter) Output(v any, headers []string, rows [][]string) error

Output writes data in the appropriate format. For JSON mode, v is encoded directly. For table/plain modes, headers and rows are used.

type Mode

type Mode int

Mode represents the output format mode.

const (
	// ModeTable outputs formatted tables (default).
	ModeTable Mode = iota
	// ModeJSON outputs JSON.
	ModeJSON
	// ModePlain outputs tab-separated values.
	ModePlain
)

func ModeFromFlags

func ModeFromFlags(jsonFlag, plainFlag bool) Mode

ModeFromFlags returns the output mode based on command flags. JSON takes precedence over plain.

func (Mode) String

func (m Mode) String() string

String returns the string representation of the mode.

Jump to

Keyboard shortcuts

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