writer

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v any, quote bool) ([]byte, error)

Convert any value to a byte array. If quote is true, then the value is quoted if it is a string.

func NewIterator

func NewIterator(v any) (*iterator, error)

NewTableMeta returns a new table metadata object, from a single struct value or an array of one or more struct values which are of the same type

func NewTableRow

func NewTableRow(Meta []ColumnMeta) *tableRow

func SizeCell

func SizeCell(cell string) (int, int)

SizeCell returns the rune width and line height of a cell

Types

type ColumnMeta

type ColumnMeta struct {
	Key     string   // the unique key of the field
	Name    string   // the name of the field
	Index   []int    // the index of the field
	Tuples  []string // the tuples from the tag
	NonZero bool     // true if there is a non-zero value in this column
	Width   int      // the maximum we column
}

func (ColumnMeta) IsAlignRight

func (m ColumnMeta) IsAlignRight() bool

type Marshaller

type Marshaller interface {
	Marshal() ([]byte, error)
}

type TableMeta

type TableMeta struct {
	Type     reflect.Type // The underlying type
	Columns  []ColumnMeta // The columns for the table
	Iterator *iterator    // The iterator for the rows
	// contains filtered or unexported fields
}

func (*TableMeta) Header

func (t *TableMeta) Header() []string

Returns a header for CSV output

func (*TableMeta) NextRow

func (t *TableMeta) NextRow() []any

Returns the next row of values, or nil if there are no more rows

func (*TableMeta) Reset

func (t *TableMeta) Reset()

Reset the iterator

func (*TableMeta) String

func (t *TableMeta) String() string

type TableOpt

type TableOpt func(*TableMeta) error

func OptCSV

func OptCSV(delim rune, header bool) TableOpt

Output CSV format, with a delimiter and optional header

func OptColumns

func OptColumns(col ...string) TableOpt

Output columns and in which order

func OptText

func OptText(delim rune, header bool, width uint) TableOpt

Output text table format, with a delimiter, optional header and width

func OptTextWidth

func OptTextWidth(width uint) TableOpt

Output text table format, with a delimiter, optional header and width

type TableWriter

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

func New

func New(w io.Writer) *TableWriter

New returns a new table writer object

func (*TableWriter) NewMeta

func (t *TableWriter) NewMeta(v any, opts ...TableOpt) (*TableMeta, error)

returns a new metadata object, from a single struct value or an array of one or more struct values which are of the same type

func (*TableWriter) String

func (t *TableWriter) String() string

func (*TableWriter) Write

func (self *TableWriter) Write(v any, opts ...TableOpt) error

Write outputs the table to a writer

type TextWriter

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

func NewTextWriter

func NewTextWriter(columns []ColumnMeta) *TextWriter

Write outputs the table to a writer

func (*TextWriter) Formatln

func (self *TextWriter) Formatln(delim rune) string

Create a format string for the writer

func (*TextWriter) Sizeln

func (self *TextWriter) Sizeln(elems []string)

Determine the maximum width of each column

func (*TextWriter) Writeln

func (self *TextWriter) Writeln(w io.Writer, format string, elems []string) error

Write a row to the writer

Jump to

Keyboard shortcuts

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