table

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: LGPL-3.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MAX_WIDTH = 65535 // 2^16 - 1
)

Variables

This section is empty.

Functions

func AlignmentCenter

func AlignmentCenter(str string, width uint16) string

func AlignmentLeft

func AlignmentLeft(str string, width uint16) string

func AlignmentRight

func AlignmentRight(str string, width uint16) string

Types

type Alignment

type Alignment = func(str string, width uint16) string

type Column

type Column struct {
	Type      reflect.Type
	Getter    Getter
	Alignment Alignment
	Name      string
	Title     string
}

type FormattedItemList

type FormattedItemList interface {
	Len() int
	Get(int) []string
}

type Getter

type Getter interface {
	Value(item any) (any, error)
	ValueString(colName string, item any) (string, error)
	Format(item any, value any) (string, error)
}

type Table

type Table struct {
	*TableSpec
	// contains filtered or unexported fields
}

func NewTable

func NewTable(spec *TableSpec) *Table

func (*Table) AlignFormattedItem

func (t *Table) AlignFormattedItem(formatted []string) ([]string, error)

func (*Table) FormatHeader

func (t *Table) FormatHeader(color string, sep string) string

func (*Table) FormatItem

func (t *Table) FormatItem(item any) ([]string, error)

func (*Table) FormatItemBasic

func (t *Table) FormatItemBasic(item any, sep string) (string, error)

FormatItemBasic formats item for non-tabular formats like json and csv using col.Getter.ValueString

func (*Table) MergeRowsHorizontal

func (t *Table) MergeRowsHorizontal(
	out io.Writer,
	items FormattedItemList,
	maxWidthArg int,
	sep string,
	compact bool,
)

func (*Table) MergeRowsVertical

func (t *Table) MergeRowsVertical(
	out io.Writer,
	items FormattedItemList,
	maxWidthArg int,
	sep string,
	compact bool,
)

func (*Table) TableWidth

func (t *Table) TableWidth(margin uint16) uint16

func (*Table) UpdateWidth

func (t *Table) UpdateWidth(widthByColumn map[string]uint16)

func (*Table) Width

func (t *Table) Width(colName string) uint16

type TableSpec

type TableSpec struct {
	ColumnByName map[string]*Column
	TimeFormat   string
	Columns      []*Column
}

func NewTableSpec

func NewTableSpec() *TableSpec

func (*TableSpec) AddColumn

func (t *TableSpec) AddColumn(col *Column)

func (*TableSpec) ColumnCount

func (t *TableSpec) ColumnCount() int

func (*TableSpec) HasColumn

func (t *TableSpec) HasColumn(colName string) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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