output

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package output provides output formatting for CLI applications. Handles table output, JSON formatting, color detection, and terminal width.

Example usage:

formatter := output.New("table", "auto", false)
tbl := formatter.NewTable("Name", "Value")
tbl.AddRow("item1", "data1").AddRow("item2", "data2")
tbl.Print()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal() bool

IsTerminal returns true if stdout is a terminal

func PrintBanner

func PrintBanner(title string)

PrintBanner prints a standard banner (for update notifications, etc.)

func PrintEmptyMessage

func PrintEmptyMessage(itemType string)

PrintEmptyMessage prints a standard "No X found" message

func PrintError

func PrintError(format string, args ...interface{})

PrintError prints a standard error message

func PrintSuccess

func PrintSuccess(format string, args ...interface{})

PrintSuccess prints a standard success message

func PrintWarning

func PrintWarning(format string, args ...interface{})

PrintWarning prints a standard warning message

func TruncateString

func TruncateString(s string, max int) string

TruncateString truncates a string to max length with ellipsis

func ValidateFormat

func ValidateFormat(format string) error

ValidateFormat checks if the format is supported

Types

type Formatter

type Formatter struct {
	Format    string
	Color     bool
	NoHeaders bool
}

Formatter handles output formatting

func New

func New(format, color string, noHeaders bool) *Formatter

New creates a new output formatter

func (*Formatter) NewTable

func (f *Formatter) NewTable(headers ...string) *TableBuilder

NewTable creates a new table builder

func (*Formatter) PrintJSON

func (f *Formatter) PrintJSON(data interface{}) error

PrintJSON outputs data as formatted JSON

type TableBuilder

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

TableBuilder helps construct tables with consistent formatting

func (*TableBuilder) AddRow

func (tb *TableBuilder) AddRow(row ...interface{}) *TableBuilder

AddRow adds a row to the table

func (*TableBuilder) Print

func (tb *TableBuilder) Print()

Print outputs the table (or raw data if NoHeaders without color)

func (*TableBuilder) PrintWithFallback

func (tb *TableBuilder) PrintWithFallback(printRaw func())

PrintWithFallback prints with fallback to raw output

Jump to

Keyboard shortcuts

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