tabular

package
v0.0.0-...-9e3a4f8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(writer io.Writer, valueList []interface{}, configurer func(*tablewriter.Table)) *tablewriter.Table

New creates a tablewriter.Table and allows customizing the table.

Each element should be a simple struct (not pointer) with a number of fields. Each field corresponds to a column in the table, the field must have json tag. The tag name is the column name in the table header.

For example: ```

type tableStruct struct {
  PartitionCount int    `json:"partition_count"`
  TableName      string `json:"name"`
}
var tables []tableStruct
...
tabular.Print(tables)

```

func NewTabWriter

func NewTabWriter(writer io.Writer, header []string) *tablewriter.Table

func Print

func Print(writer io.Writer, valueList []interface{})

Print out the list of elements in tabular form.

Types

type ColumnAttributes

type ColumnAttributes struct {
	Name string

	Attrs map[string]string
	// contains filtered or unexported fields
}

ColumnAttributes is the

type ColumnValueFunc

type ColumnValueFunc func(col *ColumnAttributes, rowData interface{}) interface{}

ColumnValueFunc takes the column value from a user record.

type CommonColumnsFunc

type CommonColumnsFunc func(rowData interface{}) []string

CommonColumnsFunc returns a list of common columns.

type Template

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

Template receives a yaml template for printing the tabular contents. A template must contain one or more sections, each is displayed as a table. A sections could contain multiple keys, each represents as the table column. Template iterates all the items in every section, one item acts as a row in the table.

func NewTemplate

func NewTemplate(template string) *Template

NewTemplate parses the given template.

func (*Template) Render

func (t *Template) Render(writer io.Writer, rows []interface{})

Render template output

func (*Template) SetColumnValueFunc

func (t *Template) SetColumnValueFunc(f ColumnValueFunc)

SetColumnValueFunc configures ColumnValueFunc

func (*Template) SetCommonColumns

func (t *Template) SetCommonColumns(columnNames []string, f CommonColumnsFunc)

SetCommonColumns sets the columns that are exactly the same among sections. This is a conveninence util to prevent repeatedly declaring the column for each section.

Jump to

Keyboard shortcuts

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