printer

package
v0.0.0-...-5dedb29 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildLine

func BuildLine(args []string) string

func BuildRows

func BuildRows(elems interface{}, fields []string) [][]string

BuildRows returns a slice of string slice Each top-level slice represents a 'row' and the values inside a given row are the columns NOTE: Not tested for non-basic types (structs,slices,maps)

Types

type TabPrinter

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

TabPrinter represents a printer that uses tab separation

func NewTab

func NewTab(w io.Writer) *TabPrinter

NewTab creates a printer for tab separated values

func (*TabPrinter) Print

func (p *TabPrinter) Print(elems interface{}, fields []string)

Print can be used to print a some fields of a struct slice, all tab separated. The `fields` slice should contain the names of the struct fields that should be printed. If a field does not exist in a given element of `elems`, it will panic If `elems` is not of a slice type, nothing will be printed.

func (*TabPrinter) PrintWithHeaders

func (p *TabPrinter) PrintWithHeaders(elems interface{}, fields []string, headers []string)

PrintWitHeaders prints using Print but with an additional header line Each element of the `headers` slice will be used to name a given tab-separated column `headers` and `fields` should be match one to one i.e. for each header there should be a field `fields` can be either a direct struct field or a method that takes no arguments and returns a single value If the `field` is a method, it should contain the `()` suffix string Examples: PrintWithHeaders(elems, []string{"Name", "Price"}, []string{"NAME","PRICE"}) PrintWithHeaders(elems, []string{"GetName()", "GetPrice()"}, []string{"NAME","PRICE"})

Jump to

Keyboard shortcuts

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