printer

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlignDefault Align = tablewriter.ALIGN_DEFAULT
	AlignCenter        = tablewriter.ALIGN_CENTER
	AlignRight         = tablewriter.ALIGN_RIGHT
	AlignLeft          = tablewriter.ALIGN_LEFT
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Align

type Align int

type Colorer

type Colorer func(string, ...interface{}) string

type PrintStructuredIter

type PrintStructuredIter interface {
	// Nil when done
	Next() (any, error)
}

type Printer

type Printer struct {
	// Must always be present
	Output io.Writer
	JSON   bool
	// This is unset/empty in JSONL mode
	JSONIndent           string
	JSONPayloadShorthand bool
	// Only used for non-JSON, defaults to RFC3339
	FormatTime func(time.Time) string
	// Only used for non-JSON, defaults to color.Magenta
	TableHeaderColorer Colorer
	// contains filtered or unexported fields
}

func (*Printer) EndList

func (p *Printer) EndList()

Must be called after Printer.StartList or will panic. See Godoc on that function for more details.

func (*Printer) Print

func (p *Printer) Print(s ...string)

Ignored during JSON output

func (*Printer) PrintStructured

func (p *Printer) PrintStructured(v any, options StructuredOptions) error

For JSON, if v is a proto message, protojson encoding is used

func (*Printer) PrintStructuredIter

func (p *Printer) PrintStructuredIter(typ reflect.Type, iter PrintStructuredIter, options StructuredOptions) error

Fields must be present for table

func (*Printer) Println

func (p *Printer) Println(s ...string)

Ignored during JSON output

func (*Printer) Printlnf

func (p *Printer) Printlnf(s string, v ...any)

Ignored during JSON output

func (*Printer) StartList

func (p *Printer) StartList()

When called for JSON with indent, this will create an initial bracket and make sure all Printer.PrintStructured calls get commas properly to appear as a list (but the indention and multiline posture of the JSON remains). When called for JSON without indent, this will make sure all Printer.PrintStructured is on its own line (i.e. JSONL mode). When called for non-JSON, this is a no-op.

Printer.EndList must be called at the end. If this is called twice it will panic. This and the end call are not safe for concurrent use.

type StructuredOptions

type StructuredOptions struct {
	// Derived if not present. Ignored for JSON printing.
	Fields []string
	// Ignored for JSON printing.
	ExcludeFields []string
	// If not set, not printed as table in text mode. This is ignored for JSON
	// printing.
	Table                        *TableOptions
	OverrideJSONPayloadShorthand *bool
}

type TableOptions

type TableOptions struct {
	// If not set for a field, maximum width of all rows for structured, and no
	// width for streaming table. Field width will always at least be field name.
	FieldWidths map[string]int
	// Fields are align-left by default
	FieldAlign map[string]Align
	NoHeader   bool
}

Jump to

Keyboard shortcuts

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