Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Tabulate ¶
Tabulate creates a string table from supplied rows. Columns are created in sorted ascending if all columns are not provided.
func WithStrict ¶
func WithStrict(v bool) option
WithStrict sets strict in options. In strict mode colums need to be defined before *Tabulator.Add call.
Types ¶
type Tabulator ¶
type Tabulator struct {
// contains filtered or unexported fields
}
func (*Tabulator) Add ¶
Add supports adding values without re-defining the column names. In non-strict mode: If amount of values is larger than the defined columns, Add creates ad-hoc dynamic column names. In strict mode: Add will panic if amount of values is larger than defined columns.
Example ¶
data := []struct { time time.Time metric string count any }{ { time: time.Time{}, metric: "a", count: 1, }, { time: time.Time{}, metric: "b", count: 20, }, { time: time.Time{}, metric: "c", count: 1.23, }, } tab := New([]string{"time", "metric", "count"}) for _, elem := range data { tab.Add(func() string { return elem.time.Format("2006-01-02T15:04") }, elem.metric, elem.count) } tab.Print(os.Stdout)
Output: | time | metric | count | |------------------|--------|-------| | 0001-01-01T00:00 | a | 1 | | 0001-01-01T00:00 | b | 20 | | 0001-01-01T00:00 | c | 1.23 |
func (*Tabulator) AddRow ¶
AddRow allows specifying columns and values. Colum names not already defined will be added at the end sorted ascending.
func (*Tabulator) Columns ¶
Columns adds specified colums to the list of columns defined for Tabulator. New columns are automatically set active to be printed if they do not already have active column specification.
func (*Tabulator) SetActiveColumns ¶ added in v0.3.0
SetActiveColumns causes only specified columns to be displayed via *Tabulator.Print
func (*Tabulator) SetActiveColumnsMap ¶ added in v0.3.0
SetActiveColumnsMap causes only specified columns where map value is true to be displayed via *Tabulator.Print