A simple library to create nested tables in the terminal.
go get github.com/data-preservation-programs/table@latest
type Person struct {
ID int
Name string
AverageScore int `table:"header:Average Score"`
Grade string `table:"color:96;headerColor:96,4"`
Scores []Score `table:"headerColor:34,4;expand"`
}
type Score struct {
Subject string
Score float32
GradedAt time.Time `table:"header:Graded At;format:2006-01-02"`
}
func main () {
fmt.Println(table.New().Render([]Person{...}))
}
header
The header string to use for the column.headerColor
The color to use for the header. The color is specified as a comma separated list of color codes. Check available values herecolor
The color to use for the column. The color is specified as a comma separated list of color codes. Check available values hereformat
The format to use for the column. Fortime.Time
, the format is specified as a Go time layout. For all other types, the format is specified as a Go format string.verbose
If set to true, the column will be displayed only when the verbose is set to true in theTable
.expand
If set to true, the column will be expanded to a sub table. The column needs to be a slice/instance/pointer to a struct.-
If specified, the column will be hidden.
Table.WithTab
Set the tab string that is appended to the sub-tables.Table.WithVerbose
Columns withverbose
tag is only displayed when the verbose is set to true.Table.WithPaddingSize
Set the padding size for each column which is the minimum padding between the columns.Table.WithHeaderRowColor
Overrides the default header row color.Table.WithFirstColumnColor
Overrides the default first column color.